![]() |
#2
newCpp2009-12-19 09:31
|

#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);
}
#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);
}
搞不懂,哪位解释下