Mutual conversion of Cstring and int, float, double, char, string data types in VC

Source: Internet
Author: User

1. Reciprocal conversion of Cstring and char*

CString turn Char

Cstring cstr= "Germany";

Char *p = (LPSTR) (LPCTSTR) CStr;

Char turn CString

Char *p = "Germany";

Cstring CStr;

Cstr.format ("%s"),
p);

2. Conversion of CString and int

CString turn int

Cstring cstr= "12345";

int A=atoi (CSTR);

int turn CString

Cstring CStr;

int a=8;

Cstr.format ("%d", a);

3. Conversion of CString and float

CString to float

Cstring cstr= "8.67";

Float A=atof (CStr);

Float Turn CString

Cstring CStr;

float a=8.00;

Cstr.format ("%.2f", a);

4. Conversion of CString and double

CString turn Double

Cstring cstr= "8.89475";

Double A=atof (CStr);

Double Turn CString

Cstring CStr;

Doulbe a=8.0067;

Cstr.format ("%.4f", a);

5. Conversion of CString and string

CString Turn string

Cstring cstr= "Germany";

String cs (CStr). GetBuffer ());

string turn CString

Cstring CStr;

String cs= "Germany";

Cstr.format ("%s"),
Cs.c_str ());

Http://www.xuebuyuan.com/1077200.html

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.