Alignment of VC string output)

Source: Internet
Author: User
If you have made data statistics in VC ProgramYou will find that alignment that was originally used to control character output in cmd does not seem to be applicable in VC.

Use printf ("% 8d", I) in cmd to output a right-aligned integer. If the number of digits is not enough, just fill the space, but use textout () in VC () in this way, when formatted string objects are output, the length of space and characters is different (the drawtext function has not been tried, but it should be the same ), therefore, the characters in the output Column cannot be aligned (for example, the column number). How can this problem be solved? First, let's look at a usage that printf and sprintf are not well-known:

Printf ("% 05d", I) is used to output a right-aligned integer. If the number of digits is not enough, add 0 to the left.

Therefore, you can use the following method to align the string:

Sprintf (TMP, "% 08d % 08d", I, j );

Cstring STR (TMP );

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.