public member function
<ios> <iostream>
basic_ios& copyfmt (const basic_ios& rhs);
Copy formatting information
Copies the values of all the internal members of rhs (except the state flags and the associated stream buffer) to the corresponding members of *this
.
After the call, the following member functions return the same for rhs and *this
:
* Each stream object keeps its own copy of the
internal extensible array (
iword,
pword): Its contents are copied, not just a pointer to it.
* Each stream object keeps its own copy of the
internal extensible array (
iword,
pword): Its contents are copied, not just a pointer to it.
If any of the pointer values to be copied points to objects stored outside
rhs and those objects are destroyed when
rhs is destroyed,
*this
stores instead pointers to newly constructed copies of these objects.
Calling this function invokes all functions registered through member register_callback twice: First, before the copying process starts, the function calls each registered callback fn using (*fn)(erase_event,*this,index)
. Then, at the end, right before the exceptions mask is copied, the function calls each registered callback fn wirh (*fn)(copyfmt_event,*this,index)
(this second round can be used, for example, to access and modify the copied internal extensible array).
Parameters
- rhs
- Stream object whose members are copied to *this.
Example
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
|
// copying formatting information
#include <iostream> // std::cout
#include <fstream> // std::ofstream
int main () {
std::ofstream filestr;
filestr.open ("test.txt");
std::cout.fill ('*');
std::cout.width (10);
filestr.copyfmt (std::cout);
std::cout << 40;
filestr << 40;
return 0;
}
|
This example outputs a number formatted in the same way to both cout and a file called "test.txt"
:
Data races
Modifies the stream object (*this
), and accesses rhs.
Concurrent access to any of the objects may cause data races.
Exception safety
Basic guarantee: if an exception is thrown, the stream is in a valid state.