?
Solved

output formating

Posted on 1998-12-12
2
Medium Priority
?
255 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 

Accepted Solution

by:
tribal9 earned 80 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

777 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