ftell函数用于确定文件位置指针从文件开头开始的当前位置的偏移字节数。 以下是一个简单的例子。
# includeiostreamusingnamespacestd; int main () file*FP=fopen ) ' mydata.txt ',' w ' ); coutftell(FP ) endl; frintf(FP,' 123 ); coutftell(FP ) endl; frintf(FP,' %d ',456 ); coutftell(FP ) endl; flose(FP ); int a; FP=fopen(mydata.txt ),) r ); coutftell(FP ) endl; FSCANF(FP,' %d ',a ); coutftell(FP ) endl; cout a endl; flose(FP ); cout'******endl; int b[10]; memset(b,0,sizeof(b ) b ); FP=fopen('YouRdata ',' wb ' ); coutftell(FP ) endl; write(b,sizeof(b ) b )、1、fp ); coutftell(FP ) endl; flose(FP ); int c[10]; FP=fopen(YouRdata,) rb ); coutftell(FP ) endl; fread(c,sizeof(c ) c )、1、fp ); coutftell(FP ) endl; flose(FP ); 返回0; }
0
3
6
0
6
123456
* * * * * * * * * * * * * * * *
0
40
0
40