std::basic_ios<CharT,Traits>::copyfmt (3) - Linux Manuals
std::basic_ios<CharT,Traits>::copyfmt: std::basic_ios<CharT,Traits>::copyfmt
Command to display std::basic_ios<CharT,Traits>::copyfmt
manual in Linux: $ man 3 std::basic_ios<CharT,Traits>::copyfmt
NAME
std::basic_ios<CharT,Traits>::copyfmt - std::basic_ios<CharT,Traits>::copyfmt
Synopsis
basic_ios& copyfmt(const basic_ios& other);
If other refers to the same object as *this, has no effects. Otherwise, copies the state of the stream other into *this. This is done in the following sequence:
1) Calls every callback registered by register_callback() passing erase_event as parameter
2) Copies all member objects from other to *this except for rdstate(), the exception mask, and rdbuf(). In particular, makes copies of the locale, the formatting flags, the contents of the arrays std::ios_base::iword and std::ios_base::pword (but not the iword and pword pointers themselves), the callbacks, and the tied stream.
3) Calls every callback registered by register_callback() passing copyfmt_event as parameter
4) Copies the exception mask from other to *this as if by calling exceptions(other.exceptions())
Parameters
other - another stream to use as source
Return value
*this
Notes
The second pass through the callbacks may be used to deep-copy the user-defined objects pointed to by the pointers in std::ios_base::pword
copyfmt() may be used to save and restore the state of a stream. Boost provides a more fine-grained IO_state_savers library for the same purpose.
Example
makes the ofstream object "out" behave exactly like std::cout, including formatting, tie() to std::cin, etc.
// Run this code
#include <iostream>
#include <fstream>
int main()
{
std::ofstream out;
out.copyfmt(std::cout); // copy everything except rdstate and rdbuf
out.clear(std::cout.rdstate()); // copy rdstate
out.basic_ios<char>::rdbuf(std::cout.rdbuf()); // share the buffer
out << "Hello, world\n";
}
Output:
Hello, world
Pages related to std::basic_ios<CharT,Traits>::copyfmt
- std::basic_ios<CharT,Traits>::clear (3) - std::basic_ios<CharT,Traits>::clear
- std::basic_ios<CharT,Traits>::bad (3) - std::basic_ios<CharT,Traits>::bad
- std::basic_ios<CharT,Traits>::basic_ios (3) - std::basic_ios<CharT,Traits>::basic_ios
- std::basic_ios<CharT,Traits>::eof (3) - std::basic_ios<CharT,Traits>::eof
- std::basic_ios<CharT,Traits>::exceptions (3) - std::basic_ios<CharT,Traits>::exceptions
- std::basic_ios<CharT,Traits>::fail (3) - std::basic_ios<CharT,Traits>::fail
- std::basic_ios<CharT,Traits>::fill (3) - std::basic_ios<CharT,Traits>::fill
- std::basic_ios<CharT,Traits>::good (3) - std::basic_ios<CharT,Traits>::good
- std::basic_ios<CharT,Traits>::imbue (3) - std::basic_ios<CharT,Traits>::imbue
- std::basic_ios<CharT,Traits>::init (3) - std::basic_ios<CharT,Traits>::init
- std::basic_ios<CharT,Traits>::move (3) - std::basic_ios<CharT,Traits>::move
- std::basic_ios<CharT,Traits>::narrow (3) - std::basic_ios<CharT,Traits>::narrow
- std::basic_ios<CharT,Traits>::operator! (3) - std::basic_ios<CharT,Traits>::operator!
- std::basic_ios<CharT,Traits>::operatorbool (3) - std::basic_ios<CharT,Traits>::operatorbool
- std::basic_ios<CharT,Traits>::rdbuf (3) - std::basic_ios<CharT,Traits>::rdbuf
- std::basic_ios<CharT,Traits>::rdstate (3) - std::basic_ios<CharT,Traits>::rdstate
- std::basic_ios<CharT,Traits>::set_rdbuf (3) - std::basic_ios<CharT,Traits>::set_rdbuf
- std::basic_ios<CharT,Traits>::setstate (3) - std::basic_ios<CharT,Traits>::setstate
- std::basic_ios<CharT,Traits>::swap (3) - std::basic_ios<CharT,Traits>::swap
- std::basic_ios<CharT,Traits>::tie (3) - std::basic_ios<CharT,Traits>::tie
- std::basic_ios<CharT,Traits>::widen (3) - std::basic_ios<CharT,Traits>::widen
- std::basic_ios<CharT,Traits>::~basic_ios (3) - std::basic_ios<CharT,Traits>::~basic_ios
- std::basic_ios (3) - std::basic_ios