C + + several ways to convert data to strings

Source: Internet
Author: User

Collect:

1\ Convert int to LPCTSTR

In fact LPCTSTR can be directly replaced with CString without type casting

CString str; intNumber= the; //str= " "Str. Format (_t ("%d"), number); //str= "15" (preceded by two spaces, 4 means 4 bits will be used, if the number exceeds 4 bits will output all numbers, will not be truncated)Str. Format (_t ("%4d"), number); //str= "0015" (. 4 means 4 bits will be consumed if the number exceeds 4 bits will output all digits and will not be truncated)Str. Format (_t ("%.4d"), number); //the method of converting a long to CString is similar to the above, just change%d to%ld. 

The format description always starts with a% character, and the following is a description of how the different types of data are formatted as% numbers:
D Output signed decimal number
o Output unsigned octal number
x output unsigned hexadecimal number
U Output unsigned number
C Output Single character
s output a string of characters
F Output Real number (6 decimal places)
E output real numbers in exponential form
G Choose the format of the output width in F and e format, do not output 0
LD input-Output Long data
LF input/output double type data
m data output width m
. n Output decimal digits N

C + + several ways to convert data to strings

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.