Reputation: 10911
Why would I use one over the other? They both seem to only affect the next field outputted. What's the point of deliberately having two ways to do the same thing? Or was one an afterthought?
Upvotes: 2
Views: 386
Reputation: 62389
std::ios_base::width()
is a member of ios_base
(ok, that's obvious), which is not typically a class that users mess around with - the intended interface for users is the *stream classes. std::setw()
works at that level (and eventually calls std::ios_base::width()
anyway). This enables the coder to write clearer code (my opinion, anyway):
cout << setw(10) << someint;
instead of:
cout.width(10);
cout << someint;
Upvotes: 1