我想從文件中讀取字符,並將它們寫入另一個。問題是,儘管所有內容都正在寫入,但在下一行寫入文件中會添加一個奇怪的符號。我的代碼是:奇怪的符號被追加到底
#include<iostream>
#include<stdlib.h>
#include<string.h>
#include<stdio.h>
using namespace std;
int main(){
FILE *f, *g;
int ch;
f = fopen("readfile", "r");
g = fopen("writefile", "w");
while(ch != EOF){
ch = getc(f);
putc(ch, g);
}
fclose(f);
fclose(g);
return 0;
}
可能是什麼原因?
你能** **請只使用[fstream的(http://en.cppreference.com/w/cpp/io/basic_fstream)? – Griwes
順便說一下,您正在使用uninited變量。 –
我發起到零,仍然發生錯誤 – newbie555