How to Format Output in C++ Using setw() and endl()

  • Thread starter Thread starter magnifik
  • Start date Start date
  • Tags Tags
    Format Program
Join the discussion
Ask a follow-up here, or get your own question answered by working scientists, mathematicians and engineers — people, not an autocomplete.
Real named experts · corrections over time · the nuance an AI answer skips
1 reply · 2K views
magnifik
Messages
350
Reaction score
0
resovledddddd
 
Last edited:
Physics news on Phys.org
Its a bit hard to see how you intend things to be lined up since your code seems to just prints everything on one line. Perhaps you should include some endl() somewhere? If you are in doubt where, make an example of how you would like the output to be and start figuring out on what "condition" you want a new line.

Also, if you use setw() to format your output you should note, that it sets the with for the next field being output. You can see a short description on [1].[1] http://www.cprogramming.com/tutorial/iomanip.html