Conversion of CString to char * in a multi-byte environment of VC

Source: Internet
Author: User

String Conversion is often used in VC programming. It can be said that string conversion is a headache for beginners and even veterans of VC. In the multi-byte environment, that is, in the ASCII environment, the following code can be used to convert Cstring to char:

CString strXcoord; GetDlgItemText (IDC_EDIT_XCOORD, strXcoord); CString strYcoord; GetDlgItemText (IDC_EDIT_YCOORD, strYcoord); if (strXcoord. isEmpty () | strYcoord. isEmpty () {AfxMessageBox (TEXT ("X and Y coordinates must be specified");} USES_CONVERSION; char * col = T2A (strXcoord. getBuffer (0); char * row = T2A (strYcoord. getBuffer (0); CString strXcoord; GetDlgItemText (IDC_EDIT_XCOORD, strXcoord); CString strYcoord; GetDlgItemText (IDC_EDIT_YCOORD, strYcoord); if (strXcoord. isEmpty () | strYcoord. isEmpty () {AfxMessageBox (TEXT ("X and Y coordinates must be specified");} USES_CONVERSION; char * col = T2A (strXcoord. getBuffer (0); char * row = T2A (strYcoord. getBuffer (0 ));

Oh, we also need strXcoord. ReleaseBuffer (); to prevent memory leakage.

 

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.