Applicable to Unicode environments from cstring to int

Source: Internet
Author: User

Cstring to int conversion (UNICODE environment)

Cstring strip;

Strip = _ T ("34 if 12 is hit ");
Int I = _ ttoi (strip );

 

 

Convert cstring type to int type

The simplest way to convert data of the cstring type to an integer type is to use a standard string to an Integer Conversion routine.
Although you usually suspect that using the _ atoi () function is a good choice, it is rarely the right choice. If you want to use Unicode
Character, you should use _ ttoi (), which is compiled into _ atoi () in the ANSI coding system, while in Unicode
In the encoding system, compile it into _ wtoi (). You can also consider using _ tcstoul () or _ tcstol (), which can convert strings into any hexadecimal long integers (such as binary, eight
Hexadecimal, decimal, or hexadecimal), the difference is that the converted data is unsigned, while the latter is opposite. See the following example:

Cstring hex = _ T ("fab ");
Cstring decimal = _ T ("4011 ");
Assert (_ tcstoul (Hex, 0, 16) = _ ttoi (decimal ));

 

 

Only Unicode is supported in EVC, so the method is as follows:
Cstring to int:
Cstring strmytry = _ T ("123 ");
Int imytry =-1;
Swscanf (strmytry, _ T ("% d"), & imytry );

Int to cstring:
Int imytry =-1;
Cstring strmytry = _ T ("");
Strmytry. Format (_ T ("% d"), imytry );

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.