Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

output formating

Posted on 1998-12-12
2
Medium Priority
?
263 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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…
  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 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 viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
Suggested Courses

636 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