Conversion between C ++ string and VC ++ CString

Source: Internet
Author: User

01 // CString to string
02 string CStringToString (const CString & cstr)
03 {
04 string str = cstr. GetBuffer (0 );
05 cstr. ReleaseBuffer ();
06 return str;
07}
08
09 void CStringToStringEx (const CString & cstr, string & str)
10 {
11 str = cstr. GetBuffer (0 );
12 cstr. ReleaseBuffer ();
13}
14
15 // string to CString
16 CString StringToCString (const string & str)
17 {
18 CString cstr = str. c_str ();
19 return cstr;
20}
21
22 void StringToCStringEx (const string & str, CString & cstr)
23 {
24 cstr = str. c_str ();
25}
26
27 // CStringA to string
28 string CStringAToString (const CStringA & cstra)
29 {
30 string str = cstra. GetBuffer (0 );
31 cstra. ReleaseBuffer ();
32 return str;
33}
34
35 void CStringAToStringEx (const CStringA & cstra, string & str)
36 {
37 str = cstra. GetBuffer (0 );
38 cstra. ReleaseBuffer ();
39}
40
41 // CStringW to string
42 string CStringWToString (const CStringW & cstrw)
43 {
44 CStringA ctsra (cstrw. GetBuffer (0 ));
45 cstrw. ReleaseBuffer ();
46 string str = cstra. GetBuffer (0 );
47 cstra. ReleaseBuffer ();
48 return str;
49}
50
51 void CStringWToStringEx (const CStringW & cstrw, string & str)
52 {
53 CStringA ctsra (cstrw. GetBuffer (0 ));
54 cstrw. ReleaseBuffer ();
55 str = cstra. GetBuffer (0 );
56 cstra. ReleaseBuffer ();
57}

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.