/* unspecified */ setw( int n );
When used in an expression out << std::setw(n) or in >> std::setw(n), sets the width
parameter of the stream out or in to exactly n.
Some operations reset the width to zero (see below), so std::setw
may need to be repeatedly called to set the width for multiple operations.
An object of unspecified type such that
where the function f is defined as:
[edit] NotesThe width property of the stream will be reset to zero (meaning "unspecified") if any of the following functions are called:
The exact effects this modifier has on the input and output vary between the individual I/O functions and are described at each operator<< and operator>> overload page individually.
[edit] Example#include <iomanip> #include <iostream> #include <sstream> int main() { std::cout << "no setw: [" << 42 << "]\n" << "setw(6): [" << std::setw(6) << 42 << "]\n" << "no setw, several elements: [" << 89 << 12 << 34 << "]\n" << "setw(6), several elements: [" << 89 << std::setw(6) << 12 << 34 << "]\n"; std::istringstream is("hello, world"); char arr[10]; is >> std::setw(6) >> arr; std::cout << "Input from \"" << is.str() << "\" with setw(6) gave \"" << arr << "\"\n"; }
Output:
no setw: [42] setw(6): [ 42] no setw, several elements: [891234] setw(6), several elements: [89 1234] Input from "hello, world" with setw(6) gave "hello"[edit] Defect reports
The following behavior-changing defect reports were applied retroactively to previously published C++ standards.
DR Applied to Behavior as published Correct behavior LWG 183 C++98setw
could only be used with streams of
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4