@StailGot
28 / 23 / 6
Регистрация: 25.08.2013
Сообщений: 41
|
02.02.2014, 15:48
|
|
C++ (Qt) | 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
| #include <fstream>
#include <iostream>
#include <memory>
#include <vector>
using namespace std;
typedef vector<unique_ptr<iostream>> iostreams_t;
template<typename _Ty>
iostreams_t & operator<<( iostreams_t & iostreams, const _Ty & val )
{
for ( size_t i = 0; i < iostreams.size(); ++i )
*iostreams[i] << val,
iostreams[i]->flush(); // для записи в файл
return iostreams;
}
int main ()
{
iostreams_t iostreams;
ofstream file( "A:/file.txt" );
iostreams.push_back( make_unique<iostream>(cout.rdbuf()) ); // консоль
iostreams.push_back( make_unique<iostream>(file.rdbuf()) ); // файл
iostreams << 42 << " " << "string";
getchar();
return 0;
} |
|
1
|