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
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
2010-09-29 18:33:27
Hmm there example doesn't seem to work.
Anteater7171
2010-09-29 19:45:25
The example doesn't actually use `std::right` anywhere.
Ben Voigt
2010-09-29 20:02:38
@Ben Voigt, Thanks dude that's why there is an OR in between the two solution options. Read before you comment.
gmcalab
2010-09-29 20:11:42
Ahh, ok: "The adjustfield flag is set to right in standard streams on initialization"
Ben Voigt
2010-09-30 02:34:45