我想从文件中读取字符,并将它们写入另一个。问题是,尽管所有内容都正在写入,但在下一行写入文件中会添加一个奇怪的符号。我的代码是:奇怪的符号被追加到底
#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