A string conversion function commonly used in VC + + programming

Source: Internet
Author: User

VC + + programming often encountered between different encoded strings need to be converted between the case, the following simple to provide several different encoded strings between the conversion function:

Conversion between ANSI string and Unicode string

//Convert Wide char string to ANSI stringBOOL Wchartombyte (lpcwstr lpcwszstr,std::string&str) {DWORD dwminsize=0; LPSTR Lpszstr=NULL; Dwminsize= WideCharToMultiByte (cp_oemcp,null,lpcwszstr,-1Null0, Null,false); if(0==dwminsize) {        returnFALSE; } lpszstr=New Char[Dwminsize]; WideCharToMultiByte (Cp_oemcp,null,lpcwszstr,-1, Lpszstr,dwminsize,null,false); STR=Lpszstr;    delete []lpszstr; returnTRUE;}//Convert ANSI string to wide char stringBOOL Mbytetowchar (lpwstr lpcwszstr,std::stringstr) {size_t size=str.length (); wchar_t*buffer=NewWchar_t[size+1]; MultiByteToWideChar (Cp_acp,null,str.c_str (), Size,buffer,size*sizeof(wchar_t)); Buffer[size]=0; Lpcwszstr=buffer;    Delete buffer; returnTRUE;}
View Code


Cond...

A string conversion function commonly used in VC + + programming

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.