Я пытаюсь одновременно писать в файл и стандартный вывод в С++, перегружая поток
тест.ч
#pragma once
#include <iostream>
using std::ofstream;
class OutputAndConsole:public ofstream
{
public:
std::string fileName;
OutputAndConsole(const std::string& fileName):ofstream(fileName),fileName(fileName){
};
template <typename T>
OutputAndConsole& operator<<(T var);
};
template <typename T>
OutputAndConsole& OutputAndConsole::operator<<(T var)
{
std::cout << var;
ofstream::operator << (var);
return (*this);
};
test.cpp
OutputAndConsole file("output.txt");
file << "test" ;
Вывод в файле
01400930
а в консоли есть
test
Я отладил код, похоже, что он входит в
_Myt& __CLR_OR_THIS_CALL operator<<(const void *_Val)
Что я делаю не так?
Cout
и у файла будут разные потоки, и что это... - person Rivasa   schedule 02.12.2012<<
для базы. - person Lightness Races in Orbit   schedule 02.12.2012