对文件的读写都忘光了。前些天酷派的笔试有个题就是把文件中的内容读出并计算。他的意思是将文件中的16进制数读出,但当时只想到文件中存的是字节。。。
1.fgetc
FILE *f=fopen("exist",r);
char ch;
while(ch=fgetc(f)!=EOF)
printf("%c",ch);
fclose(ch);
}
2. c++ fstream ifstream ofstream
fstream fout("exist",ios::in);//fstream默认以ios::in方式打开文件,也就是以读文件的方式
ifstream fout("exist",ios::in);//ifstream默认以ios::in方式打开文件,也就是以读文件的方式
ostream fout("exist",ios::out);//ofstream默认以ios::in方式打开文件,也就是以写文件的方式
while(!f.eof())
{
fout>>ch;
printf("%c",ch);
}
f.close();
}