Reference

public member function
<ios> <iostream>

std::basic_ios::copyfmt

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:
elementdescription
flags format flags
width field width
precision precision
getloc selected locale
iarray internal extensible array *
parray internal extensible array *
fill fill character
tie tied stream
exceptions exceptions mask (last to be copied, see below)

* 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.

Return Value

*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":
********40


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.

See also

basic_ios::tie
Get/set tied stream (public member function)
basic_ios::fill
Get/set fill character (public member function)
ios_base::width
Get/set field width (public member function)
ios_base::fmtflags
Type for stream format flags (public member type)

AltStyle によって変換されたページ (->オリジナル) /