Solved

output formating

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

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…
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 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 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.

757 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now