2

i am trying to create a logger class that redirects std::cout to a log file and OutputDebugStringA() at the same time.

my code uses a library that uses std::cout for debugging purposes, but i don't want to use the standard console because my code uses the windows subsystem and i want to output to visual studio's output window, but i want to log those messages that are redirected to the output window , to a simple text file , i know how to redirect cout to the output window, but i don't know how to print cout to a file and the output window at the same time.

struct Logger : public std::stringbuf{
  Logger(){
     std::cout.rdbuf(this);
  }
  
  ~Logger(){
     this->sync();
  }
  int sync(){
     ::OutputDebugStringA(str().c_str());
     str(std::string());
     return 0;
  }
};
  • Does this answer your question? [trying to write std:out and file at the same time](https://stackoverflow.com/questions/13665090/trying-to-write-stdout-and-file-at-the-same-time) – Gnqz Jun 14 '22 at 09:09
  • the visual studio output is different from the normal console, – Bardia Bahrampour Jun 14 '22 at 09:18

0 Answers0