title: Get current username in C++ on Windows
body: <p>I am attempting to create a program that retrieves the current user's username on Windows using C++.</p>
  
  <p>I tried this:</p>
  
  <pre><code>char *userName = getenv("LOGNAME");
  stringstream ss;
  string userNameString;
  ss &lt;&lt; userName;
  ss &gt;&gt; userNameString;
  cout &lt;&lt; "Username: " &lt;&lt; userNameString &lt;&lt; endl;
  </code></pre>
  
  <p>Nothing is outputted except "Username:".</p>
  
  <p>What is the simplest, best way to get the current username?</p>