Home > Software engineering >  Vc problem, why this happens
Vc problem, why this happens

Time:09-16

I use simple Visual Studio 2010 to the output file the helloworld

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 + 1

CodePudding user response:

3/f is wrong, should be
Int 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 sizeof

CodePudding 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 error

CodePudding user response:

//a notepad for unicode
CFile 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 ();
  • Related