Difference between revisions of "cpp/io/manip/resetiosflags"
From cppreference.com
m (simplify) |
Andreas Krug (Talk | contribs) m (headers sorted) |
||
(One intermediate revision by one user not shown) | |||
Line 1: | Line 1: | ||
{{cpp/title|resetiosflags}} | {{cpp/title|resetiosflags}} | ||
{{cpp/io/manip/navbar}} | {{cpp/io/manip/navbar}} | ||
− | {{ddcl | header=iomanip | | + | {{ddcl|header=iomanip| |
/*unspecified*/ resetiosflags( std::ios_base::fmtflags mask ); | /*unspecified*/ resetiosflags( std::ios_base::fmtflags mask ); | ||
}} | }} | ||
− | When used in an expression {{c|out << resetiosflags(mask)}} or {{c|in >> resetiosflags(mask)}}, clears all format flags of the stream {{ | + | When used in an expression {{c|out << resetiosflags(mask)}} or {{c|in >> resetiosflags(mask)}}, clears all format flags of the stream {{c|out}} or {{c|in}} as specified by the {{c|mask}}. |
===Parameters=== | ===Parameters=== | ||
{{par begin}} | {{par begin}} | ||
− | {{par | mask | bitmask of the flags to clear}} | + | {{par|mask|bitmask of the flags to clear}} |
{{par end}} | {{par end}} | ||
===Return value=== | ===Return value=== | ||
− | + | {{cpp/io/manip/iomanip return value|resetiosflags}} | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | }} | + | |
===Example=== | ===Example=== | ||
{{example | {{example | ||
− | + | |code= | |
− | + | #include <iomanip> | |
+ | #include <iostream> | ||
#include <sstream> | #include <sstream> | ||
− | + | ||
− | + | ||
int main() | int main() | ||
{ | { | ||
std::istringstream in("10 010 10 010 10 010"); | std::istringstream in("10 010 10 010 10 010"); | ||
int n1, n2; | int n1, n2; | ||
+ | |||
in >> std::oct >> n1 >> n2; | in >> std::oct >> n1 >> n2; | ||
− | std::cout << "Parsing \"10 010\" with std::oct gives: | + | std::cout << "Parsing \"10 010\" with std::oct gives: " << n1 << ' ' << n2 << '\n'; |
+ | |||
in >> std::dec >> n1 >> n2; | in >> std::dec >> n1 >> n2; | ||
− | std::cout << "Parsing \"10 010\" with std::dec gives: | + | std::cout << "Parsing \"10 010\" with std::dec gives: " << n1 << ' ' << n2 << '\n'; |
+ | |||
in >> std::resetiosflags(std::ios_base::basefield) >> n1 >> n2; | in >> std::resetiosflags(std::ios_base::basefield) >> n1 >> n2; | ||
std::cout << "Parsing \"10 010\" with autodetect gives: " << n1 << ' ' << n2 << '\n'; | std::cout << "Parsing \"10 010\" with autodetect gives: " << n1 << ' ' << n2 << '\n'; | ||
} | } | ||
− | + | |output= | |
− | Parsing "10 010" with std::oct gives: | + | Parsing "10 010" with std::oct gives: 8 8 |
− | Parsing "10 010" with std::dec gives: | + | Parsing "10 010" with std::dec gives: 10 10 |
Parsing "10 010" with autodetect gives: 10 8 | Parsing "10 010" with autodetect gives: 10 8 | ||
}} | }} | ||
+ | |||
+ | ===Defect reports=== | ||
+ | {{dr list begin}} | ||
+ | {{dr list item|wg=lwg|dr=183|std=C++98|before={{tt|resetiosflags}} could only be used with<br>streams of type {{lc|std::ostream}} or {{lc|std::istream}}|after=usable with any<br>character stream}} | ||
+ | {{dr list end}} | ||
===See also=== | ===See also=== | ||
{{dsc begin}} | {{dsc begin}} | ||
− | {{dsc inc | cpp/io/ios_base/dsc setf}} | + | {{dsc inc|cpp/io/ios_base/dsc setf}} |
− | {{dsc inc | cpp/io/manip/dsc setiosflags}} | + | {{dsc inc|cpp/io/manip/dsc setiosflags}} |
{{dsc end}} | {{dsc end}} | ||
{{langlinks|de|es|fr|it|ja|pt|ru|zh}} | {{langlinks|de|es|fr|it|ja|pt|ru|zh}} |
Latest revision as of 22:54, 15 September 2023
Defined in header <iomanip>
|
||
/*unspecified*/ resetiosflags( std::ios_base::fmtflags mask ); |
||
When used in an expression out << resetiosflags(mask) or in >> resetiosflags(mask), clears all format flags of the stream out or in as specified by the mask.
Contents |
[edit] Parameters
mask | - | bitmask of the flags to clear |
[edit] Return value
An object of unspecified type such that
- if out is an object of type std::basic_ostream<CharT, Traits>, the expression out << resetiosflags(mask)
- has type std::basic_ostream<CharT, Traits>&
- has value out
- behaves as if it called f(out, mask)
- if in is an object of type std::basic_istream<CharT, Traits>, the expression in >> resetiosflags(mask)
- has type std::basic_istream<CharT, Traits>&
- has value in
- behaves as if it called f(in, mask)
where the function f is defined as:
void f(std::ios_base& str, std::ios_base::fmtflags mask) { // reset specified flags str.setf(ios_base::fmtflags(0), mask); }
[edit] Example
Run this code
#include <iomanip> #include <iostream> #include <sstream> int main() { std::istringstream in("10 010 10 010 10 010"); int n1, n2; in >> std::oct >> n1 >> n2; std::cout << "Parsing \"10 010\" with std::oct gives: " << n1 << ' ' << n2 << '\n'; in >> std::dec >> n1 >> n2; std::cout << "Parsing \"10 010\" with std::dec gives: " << n1 << ' ' << n2 << '\n'; in >> std::resetiosflags(std::ios_base::basefield) >> n1 >> n2; std::cout << "Parsing \"10 010\" with autodetect gives: " << n1 << ' ' << n2 << '\n'; }
Output:
Parsing "10 010" with std::oct gives: 8 8 Parsing "10 010" with std::dec gives: 10 10 Parsing "10 010" with autodetect gives: 10 8
[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++98 | resetiosflags could only be used withstreams of type std::ostream or std::istream |
usable with any character stream |
[edit] See also
sets specific format flag (public member function of std::ios_base )
| |
sets the specified ios_base flags (function) |