C + + ways to convert data to strings _c language

Source: Internet
Author: User

Collect:

1\ int to LPCTSTR

In fact, LPCTSTR can be directly replaced with CString without type cast

  CString str;
int number=15;
Str= "str"
.  Format (_t ("%d"), number);
Str= "15" (preceded by two spaces; 4 indicates that 4 digits will be occupied, and if the number exceeds 4, it will output all numbers and will not truncate)
str.  Format (_t ("%4d"), number);
Str= "0015" (. 4 indicates that 4 bits will be occupied, and if the number exceeds 4 digits will output all digits, not truncate)
str.  Format (_t ("%.4d"), number);
A long conversion to CString is similar to the above, with the need to change%d to%ld.

The format description always starts with a% character, and the following is a description of the format of different types of data:
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 digits)
e outputting real numbers in exponential form
G Choose the format of F and e format with smaller output width, no output 0
LD input-Output Long data
LF input and output double type data
M data output width is M
. n Outputs a decimal number of n

The above mentioned is the entire content of this article, I hope you can enjoy.

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.