fopen会破坏堆内存?我不相信,大侠们帮我看看怎么回事?
项目工程采用Unicode编码
测试程序:
TCHAR * pStr = _T("A01,2,3|货位编码~可存数量~已存数量^货位编码~可存数量~已存数量^货位编码~可存数量~已存数量"); int len = _tcslen(pStr); char * p1 = new char(len*2 + 2); //char p1[200]; memcpy(p1, pStr, len*2); FILE * fp = fopen("Write_File.dat", "w+b"); if (!fp) return; fseek(fp, 0, SEEK_SET); int n = 0; n = fwrite(p1, sizeof(char), len*2, fp); fseek(fp, 0, SEEK_SET); char * p2 = new char(500); n = fread(p2, sizeof(char), len*2, fp); fclose(fp); // ...
char * p1 = new char[len*2 + 2];
[解决办法]
fopen supports Unicode file streams. To open a Unicode file, pass a ccs flag that specifies the desired encoding to fopen, as follows.fopen(&fp, "newfile.txt", "rw, ccs= encoding ");
[解决办法]
char * p1 = new char(len*2 + 2);
--》
char * p1 = new char[len*2 + 2];
[解决办法]
你把"Write_File.dat"和"w+b"用中间变量传递一下,看看结果有什么不同。
[解决办法]
帮顶一下吧,最好用windbg调试看看,或者别用fopen,直接用CreateFile试试
[解决办法]
[解决办法]
这个还真是容易犯得问题,记下了。