Solved

output formating

Posted on 1998-12-12
2
229 Views
Last Modified: 2010-04-02
I have to format into columns
I have a numbered list and when the numbers get into two digits the next colum is offset.
any tricks to take care of this.
and a easier way to do columns
the way I am doing it know:

cout<<data<<"      "<<more_data<<"       "<<endl;

Thanks for the help.
0
Comment
Question by:strmtrpr
2 Comments
 

Accepted Solution

by:
tribal9 earned 20 total points
ID: 1180026
You can format output using <iomanip.h>, it's a standard header file.  Specifically you can use the setw(x) function.

int data = 50, data2 = 5;

cout << setw(3) << data << setw(3) << data2 << endl;

You use setw(x) like the endl operator.  It sets aside a "column" x spaces wide, and places everything to the far right of that column.  If the output needs more spaces than the column provides (e.g. data = 5000) then it will flood over and mess it up.

Matt
matt@anji.smhall.org



0
 

Author Comment

by:strmtrpr
ID: 1180027
thanks for the help
0

Featured Post

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Dialogbox API leak? 18 94
Add values of each row in an array 3 57
Why isn't object file created? 6 58
How to convert Structure to vector of byte and vice versa 5 14
In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question