C ++ writes the ANSI and Unicode encoding of Text

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.