Solved

output formating

Posted on 1998-12-12
2
249 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 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

Enroll in June's Course of the Month

June’s Course of the Month is now available! Experts Exchange’s Premium Members, Team Accounts, and Qualified Experts have access to a complimentary course each month as part of their membership—an extra way to sharpen your skills and increase training.

Question has a verified solution.

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

Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…

688 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