1. In vs2010, the characters in the cstring type are wide characters.
2. Write the cstring to an ANSI-encoded TXT file:
Cstring szchar = l "";
Szchar = setlocale (lc_ctype, ("CHS "));
Cstdiofile * file = new cstdiofile (atxtfilename, cfile: modecreate | cfile: modewrite); // atxtfilename indicates the TXT file path.
Cstring Info;
Getdlgitemtext (idc_font, Info); // obtain the content entered in the text box.
File-> writestring (info. getbuffer ());
File-> close ();
Delete file;
At this time, the TXT file uses ANSI (Multi-Byte Character Set) encoding.
3. Write the cstring into the Unicode-encoded TXT file:
Cstring Info;
Getdlgitemtext (idc_font, Info );
Cfile;
Cfile. Open (_ T ("D: \ 1.txt"), cfile: modewrite | cfile: modecreate );
// Starts with a file
Cfile. seektobegin ();
Cfile. Write ("\ xFF \ xfe", 2 );
// Write content
Cfile. Write (Info, info. getlength () * sizeof (wchar_t ));
Cfile. Flush ();
Cfile. Close ();
In this case, the TXT file uses Unicode (wide character) encoding.