Conversion between MFC cstring,string,char*

Source: Internet
Author: User

Knowledge Point: CString turn char*,stringstring Turn char*, CStringChar* Turn CString,stringOne, CString turn char*,string    //String Conversion testCString CString1; STD::stringstring1; CHAR* char1=NULL; //1string1=Cstring1.getbuffer ();    Cstring1.releasebuffer (); //2char1=Cstring1.getbuffer (); Cstring1.releasebuffer (); second, string to char*, CString//1cstring1=String1.data (); //2char1=NewChar[string1.length () +1]; strcpy (Char1,string1.data ()); third, CHAR*Turn cstringwstring CString1=char1; String1=char1; ////TODO: Add control notification handler code here    //CString cstring1= "CString"; //std::string string1= "string"; //CHAR * char1= "char1";    ////One, CString string, char*    //string1=cstring1; //Char1=cstring1.getbuffer (); //Cstring1.releasebuffer ();//releasing a string buffer    ////Two, string to CString char*    //string1= "string1"; //Cstring1=string1.data ();    ////char1=string1.data ();    //new Char[string1.length () +1]; //strcpy (Char1,string1.data ());    ////Three, char* turn CString, String    //char1= "Char1"; //cstring1=char1; //string1=char1;    ////TODO: Add control notification handler code here    //CString cstring1=l "CString"; //std::wstring string1=l "string"; //WCHAR * char1=l "char1";    ////One, CString string, char*    //string1=cstring1; //Char1=cstring1.getbuffer (); //Cstring1.releasebuffer ();//releasing a string buffer    ////Two, string to CString char*    //string1=l "string1"; //Cstring1=string1.data ();    ////char1=string1.data ();    //new Wchar[string1.length () +1]; //wcscpy (Char1,string1.data ());    ////Three, char* turn CString, String    //char1=l "Char1"; //cstring1=char1; //string1=char1; //TODO: Add control notification handler code hereCString cstring1= _t ("CString"); STD::stringstring1=_t ("string"); TCHAR* CHAR1=_T ("char1"); //one, CString string, char*string1=CString1; Char1=Cstring1.getbuffer (); Cstring1.releasebuffer ();//releasing a string buffer//Second, string to CString char*string1=_t ("string1"); CString1=String1.data (); //Char1=string1.data ();    NewTchar[string1.length () +1];    strcpy (Char1,string1.data ()); //third, char* turn CString, Stringchar1=_t ("char1"); CString1=char1; String1=CHAR1;

Conversion between MFC cstring,string,char*

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.