CFile test_file;
Test_file. Open (_T ("./test. TXT "), CFile: : modeCreate | CFile: : modeWrite);
Test_file. Write (" helloworld, "sizeof (" helloworld"));
Test_file. Write (" helloworld, "strlen (" helloworld"));
Test_file. Write (" helloworld, "sizeof (" helloworld"));//have this line will appear garbled, no normal
Test_file. Close ();
CodePudding user response:
_T ("./test. TXT ")_T (". \ \ test TXT ")
CodePudding user response:
Sizeof (helloworld \ "0")CodePudding user response:
Sizeof (" helloworld "), the lack of a 0 (sz)CodePudding user response:
String ends in '\ 0', sizeof to + 1CodePudding user response:
3/f is wrong, should beInt n=sizeof (" helloworld ");//10 + '0'
Is more than a 0 strlen;
The 0 is written to the file TXT file garbled words,
CodePudding user response:
Should use strlen, not sizeofCodePudding user response:
Encoding format of the questions, when the last line to join, stored data length is 32 bit, notepad for unicode and actually written to the file is multi-byte, if the length is not a multiple of 16, or every string to '\ 0' at the end, will not parse errorCodePudding user response:
//a notepad for unicodeCFile test_file;
Test_file. Open (" test. TXT ", CFile: : modeCreate | CFile: : modeWrite);
Test_file. Write (" Ha ", sizeof (" Ha "));//3 (+ 0)
Test_file. Write (" H ", strlen (" H "));//1
Test_file. Close ();