title: Overwrite std::cin read-buffer after reading password
body: <p>After reading a password from std::cin</p>
  <pre><code>std::cout &lt;&lt; &quot;Password: &quot;;
  SecureString pw{}; // secure string, wipes automatically on destruction
  SetConsoleEcho(false); // hide input in terminal
  std::getline(std::cin, pw); // input the password
  SetConsoleEcho(true); // switch echo back on
  </code></pre>
  <p>the password stays stored in the read buffer of cin (heap memory) until it is overwritten with new input and can easily be sniffed with tools like Process Hacker or would be written to disk in case of a memory dump.</p>
  <p>Does anyone know how the std::cin.rdbuf() can be cleared/overwritten, ideally in a cross-platform way? Or is there a way how to avoid using the buffer in the first place?</p>
  <p>The above code uses SecureString which is implemented using Crypto++'s AllocatorWithCleanup which wipes memory at destruction. SetConsoleEcho switches the console echo on/off in order to avoid seeing the plain text password on screen.</p>
  <p>I realize this question is very similar to <a href="https://stackoverflow.com/questions/1852801/how-do-i-modify-the-internal-buffer-of-stdcin">this one</a> but it's been over 10 years and the accepted answer actually does not answer the question.</p>