title: C++ Change working Directory from User Input
body: <p>I'm designing a mock shell program, and I can't quite mimic the "cd" command. I've tried chdir(), but that wasn't working, so I moved on to trying to change the environmental variable "PWD="</p>
  
  <p>Here's what I have, and I think this may be close. (Please, please, correct me if I'm wrong or was closer with chdir())</p>
  
  <pre><code>else if (command == "cd")
          {
              string pathEnv = "PWD=";
              string newDir;
              cin &gt;&gt; newDir;
              pathEnv+=newDir;
              cout &lt;&lt; pathEnv &lt;&lt; endl;
              putenv(pathEnv.c_str());
          }
  </code></pre>
  
  <p>Hopefully the command would be 'cd /user/username/folder' and my pathEnv variable would be "PWD=/user/username/folder" which would maybe change the directory?</p>
  
  <p>Any insight is greatly appreciated.</p>