Convert cstring to another type

Source: Internet
Author: User

Cstring CSTR = l "1 ";

Cstring to int I;
I = _ ttoi (CSTR );
I = atoi (const char *) CSTR );
I = atoi (char *) CSTR );
// Atoi, _ atoi64, or atol

Cstring to float F;
Sscanf (STR, "% F", & V); // float V;

Double dval = atof (lpctstr (STR ));

 

Cstring to string STR;
String STR (Str. getbuffer (); // remember to use Str. releasebuffer (); to release space

 

Cstring to char * Ch;
Ch = CSTR. getbuffer (CSTR. getlength ());
Ch = (lpcstr) CSTR;
Ch = (char *) (lpcstr) CSTR;
Ch = (char *) (lpctstr) CSTR;
Ch = (lpstr) (lpctstr) CSTR;
Char * basicfunction: stringtocharx (cstring Str)
{
Int Len = widechartomultibyte (cp_acp, 0, STR, str. getlength (), null, 0, null, null );
Char * pascii = new char [Len + 1];
Len = widechartomultibyte (cp_acp, 0, STR, str. getlength (), pascii, Len + 1, null, null );
Pascii [Len] = 0;
Return pascii;
}

Cstring to Char [100];
Strncpy (A, (lpctstr) CSTR, sizeof ());

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.