菜鸟有疑问~~读取文件搞不懂哪里出错了~
程序代码:
#include <iostream> #include <stdlib.h> using namespace std; void main() { FILE *fp; char ch; if ( (fp = fopen("kid.txt","wr+")) == NULL) { cout << "Can not open the file!" << endl; system("pause"); exit(1); } cout << "Input the string :" <<endl; ch = getchar(); while ( ch != '\n') { fputc(ch,fp); ch = getchar(); } rewind(fp); //执行时,下列代码好像没有执行 ch = fgetc(fp); while ( ch != EOF) { putchar(ch); ch = fgetc(fp); } fclose(fp); }
搞不懂,哪位解释下