如果我跑:
FILE* pFile = fopen("c:\\08.bin", "r");
fpos_t pos;
char buf[5000];
int ret = fread(&buf, 1, 9, pFile);
fgetpos(pFile, &pos);
Run Code Online (Sandbox Code Playgroud)
我得到ret = 9和pos = 9.
但是,如果我跑
FILE* pFile = fopen("c:\\08.bin", "r");
fpos_t pos;
char buf[5000];
int ret = fread(&buf, 1, 10, pFile);
fgetpos(pFile, &pos);
Run Code Online (Sandbox Code Playgroud)
ret = 10如预期的那样,但是pos = 11!
怎么会这样?
小智 8
您需要以二进制模式打开文件:
FILE * pFile = fopen("c:\\08.bin", "rb");
Run Code Online (Sandbox Code Playgroud)
不同之处在于读取库认为是换行符并扩展它的字符 - 二进制模式阻止扩展.
| 归档时间: |
|
| 查看次数: |
540 次 |
| 最近记录: |