首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C语言 >

求c io高手解答,该如何处理

2012-06-05 
求c io高手解答今天回来遇到一问题,C/C++ code//1.txt文件大小为1444byte//windows :#include io.h//lin

求c io高手解答
今天回来遇到一问题,

C/C++ code
//1.txt文件大小为1444byte//windows :#include <io.h>//linux #include <unistd.h>#include <fcntl.h>/*#include <stdio.h>*/int main(void){//    FILE * file = fopen("f:/temp/1.txt", "rb");    int fd = 0;    char buff[1024];    int reads = 0;    int counts = 0;//    fd = file->_file;    fd = _open("f:/temp/1.txt", O_RDONLY, 0777);    while ((reads = _read(fd, buff, sizeof(buff))) > 0) {        counts += reads;    }    reads += 0;    return 0;}//xp3下vs2008,counts 为1408, ubuntu 12.04下gcc,counts为1444


[code=C/C++][/code]

C/C++ code
// #include <io.h>// #include <fcntl.h>#include <stdio.h>int main(void){    FILE * file = fopen("f:/temp/1.txt", "rb");    int fd = 0;    char buff[1024];    int reads = 0;    int counts = 0;    fd = file->_file;//    fd = _open("f:/temp/1.txt", O_RDONLY, 0777);    while ((reads = _read(fd, buff, sizeof(buff))) > 0) {        counts += reads;    }    reads += 0;    return 0;}//xp3下vs2008,counts 为1444


真心伤不起,以前只是听说window对c标准支持不够,这回不知道是不是这个问题,请各位各抒己见,谢谢。
很久不灌水,分不多。全部家当,哈哈。

[解决办法]
跟你打开文件的模式有关的吧。第二个例子中是按照binary打开的,第一个没有写明,默认应该是text。
你第一个例子中打开文件是加上_O_BINARY说不定结果会不一样。

热点排行
Bad Request.