Sunday, July 12, 2009

How to set columns in output in C++?

I am a beginner programmer. I have a C++ program where you have to display numerical and writing in set columns. Is there a way to do that in C++?

How to set columns in output in C++?
You can do that by figuring out the maximum number of characters you need in order to make the columns, and keep track of the length of the variables you put on the screen, including the text.





Example:


Field1 Field2 Field3


Person Person Person





In each field, we have a piece of information called "Person". Since all of the fields have a length of 7, and person has a length of 6, I only added one space after the data of "Person" to make it equal to the column width of 7. This way they all line up!





Hope this helps.


No comments:

Post a Comment