versuchen, std: out zu schreiben und gleichzeitig abzulegen

Ich versuche, in Datei und stdout gleichzeitig in C ++ zu schreiben, indem ich ofstream überlade

test.h

 #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" ;

Die Ausgabe in der Datei ist

01400930

aber in der konsole ist

test

Ich habe den Code debuggt, anscheinend wird er gerade eingegeben

_Myt& __CLR_OR_THIS_CALL operator<<(const void *_Val)

Was mache ich falsch?

Antworten auf die Frage(2)

Ihre Antwort auf die Frage