C ++ string, number conversion, string number Conversion

Source: Internet
Author: User

C ++ string, number conversion, string number Conversion

1: strL. format ("% x", 12); // converts a number 12 to a hexadecimal character (C) stored in strL 2: strH. format ("% x", 12); // converts a number 12 to a hexadecimal character (C) stored in strH 3: strHL = strH + strL; // connect two characters 4: sscanf_s (strHL, "% x", & intHL); // convert the character string (hexadecimal) to a decimal integer 5: strHL. format ("% d", intHL); // convert the string to a 10-digit integer 6: MessageBox (strHL );

 

 

Summary
1. The Format function can convert numbers to strings.
2. The sscanf_s function can convert strings to numbers.
3. When using sscanf_s, pay attention to the previous string format, for example, strHL is "cc" and 0xCC
The second parameter of sscanf_s should be "% x" instead of "% d"

Source: http://www.cnblogs.com/douzi2/

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.