title: Accessing linux user home directory with fstream
body: <p>I am writing small c++ code to access and edit certain text file in user's home directory. Currently I have following code (this is the relevant part):</p>
  
  <pre><code>bool core(void) {
      std::string autostart_entry = "";
      std::string user_entry = "";
      std::fstream username;
      username.open("username.txt", std::fstream::in);
      std::string location;
      std::string user_name;
      if (username.fail()) {
          username.open("username.txt", std::fstream::out);
          std::cout &lt;&lt; "What's your system username? ";
          std::getline(std::cin, user_name);
          username &lt;&lt; user_name;
      }
      else
          username &gt;&gt; user_name;
      username.close();
      location = "/home/" + user_name + "/.config/openbox/autostart";
      ...
  }
  </code></pre>
  
  <p>This way, as you can see, I ask user for his username, and append it to the location string, is there any easy way to find user's home directory without asking for user's input? I have tried "~/..." and it doesn't work.</p>
  
  <p>I know I could scan "/etc/passwd" file to find it from there but I am wondering if there is another way.</p>