I need to print a text like this:

10000: 1 1: 55 1204: 312 

Can't format text,

 cout << right << "job: " << setw(10) << 20 << endl; 

That's not how it works. Tell me please! I know that the decision is somewhere on the surface, but I just can not finish it.

Update

Nothing changes. Maybe I incorrectly expressed my thought when I gave this line as an example, but I mean that I want to achieve the formatted text given above.

In general, I need to get this code formatted:

 fout << setw(5) << "fname: " << setw(15) << fname << endl; fout << setw(5) << "lname: " << setw(15) << lname << endl; fout << setw(5) << "job: " << setw(15) << job << endl; 
  • What does "not working" mean? - alexlz
  • Updated the question - dbs1024 '15

1 answer 1

Your field size ( setw() ) is smaller than the data size, and therefore it does not work.

Code:

 cout << setw(10) << "xaxa: " << setw(10) << 22 << '\n'; cout << setw(10) << "xa: " << setw(10) << 1122 << '\n'; cout << setw(10) << "xa-xaxa: " << setw(10) << 2 << '\n'; 

displays

  xaxa: 22 xa: 1122 xa-xaxa: 2