Reputation: 1664
I wanna output a matrix in right-justified fields of length 8 in C++.
Is there any facility to make that easy to code?
Upvotes: 0
Views: 2048
Reputation: 3351
You can use std::right and std::setw to get right justified fields in iostream. The default padding char is space, but you can change it with setfill()
. Also, right
isn't strictly necessary as I believe it is the default, but it's nice to be explicit.
std::cout << std::right << std::setw(8) << data_var
Upvotes: 5
Reputation: 12205
Yes
std::right
will right justify and
std::setw(8)
will set the field width to 8.
Upvotes: 1