Namespaces
Variants
Views
Actions

Difference between revisions of "cpp/io/manip/resetiosflags"

From cppreference.com
< cpp‎ | io‎ | manip
m (simplify)
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 {{tt|out}} or {{tt|in}} as specified by the {{tt|mask}}.
+
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}}
Returns an object of unspecified type such that if {{tt|str}} is the name of a stream of type {{c|std::basic_ostream<CharT, Traits>}} or {{c|std::basic_istream<CharT, Traits>}}, then the expression {{c|str << resetiosflags(mask)}} or {{c|str >> resetiosflags(mask)}} behaves as if the following code was executed:
+
 
+
{{c|1=
+
str.setf(std::ios_base::fmtflags(0), mask);
+
}}
+
  
 
===Example===
 
===Example===
 
{{example
 
{{example
|
+
|code=
| code=
+
#include <iomanip>
 +
#include <iostream>
 
#include <sstream>
 
#include <sstream>
#include <iostream>
+
 
#include <iomanip>
+
 
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: " << n1 << ' ' << n2 << '\n';
+
     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: " << n1 << ' ' << n2 << '\n';
+
     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=
+
|output=
Parsing "10 010" with std::oct gives: 8 8
+
Parsing "10 010" with std::oct gives: 8 8
Parsing "10 010" with std::dec gives: 10 10
+
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

 
 
 
Input/output manipulators
Floating-point formatting
Integer formatting
Boolean formatting
Field width and fill control
Other formatting
Whitespace processing
Output flushing
(C++20)  

Status flags manipulation
resetiosflags
Time and money I/O
(C++11)
(C++11)
(C++11)
(C++11)
Quoted manipulator
(C++14)
 
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

#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 with
streams 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) [edit]
sets the specified ios_base flags
(function) [edit]