tags:

views:

68

answers:

1

How do I format my console output so that it's aligned to the right in C++?

+4  A: 

Use the manipulator flag std::right

Example

or

This works...

#include<iostream>
using std::cout;
using std::endl;


#include<iomanip>
using std::setw;

int main(){

 int x = 12345;

 cout << "Blah Blah Blah" << endl << setw(80) <<  x << endl;

 system("pause");

 return 0;
}
gmcalab
Hmm there example doesn't seem to work.
Anteater7171
The example doesn't actually use `std::right` anywhere.
Ben Voigt
@Ben Voigt, Thanks dude that's why there is an OR in between the two solution options. Read before you comment.
gmcalab
Ahh, ok: "The adjustfield flag is set to right in standard streams on initialization"
Ben Voigt