title: Redirecting cout to the new buffer that created with winapi
body: <p>I'm trying to print to the new screen buffer that i've create with winapi but it's going to the old buffer and doesn't show up on the screen, is it possible, redirecting <code>cout</code> to the new screen buffer that created by using winapi?</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;Windows.h&gt;
  
  int main() {
      HANDLE stdBuf, nBuf;
      DWORD numberOfChars;
  
      stdBuf = GetStdHandle(STD_OUTPUT_HANDLE);
      nBuf = CreateConsoleScreenBuffer(GENERIC_WRITE, 0, NULL, CONSOLE_TEXTMODE_BUFFER, NULL);
  
      SetConsoleActiveScreenBuffer(nBuf);
      SetStdHandle(STD_OUTPUT_HANDLE, nBuf);
  
      // THIS SHOWING UP ON THE SCREEN
      WriteConsole(nBuf, "SECOND BUFFER", 13, &amp;numberOfChars, NULL);
  
      // THIS IS GOING TO THE FIRST BUFFER
      std::cout &lt;&lt; "SECOND BUFFER with cout" &lt;&lt; std::endl;
  
      Sleep(3000);
  
      SetConsoleActiveScreenBuffer(stdBuf);
      CloseHandle(nBuf);
  
      int a = 0;
      std::cin &gt;&gt; a;
      return 0;
  }
  </code></pre>