How to pass a string to ofstream::open for the file name
<p>This is my first C++ app. I'm using Visual C++ 2010 Express. I'm trying to write a console program that will write the line "alive" to the file alive.txt on my WD USB hard drive every 10 seconds to prevent the drive from spinning down.  I want the program to prompt me for the drive letter, and then use that to tell the program where the file is located.  This works:</p>

<pre><code>while (true)
{
Sleep(5000);
cout &lt;&lt; "Past sleep";
ofstream AliveFile;
AliveFile.open ("j:\\alive.txt");
AliveFile &lt;&lt; "alive" &lt;&lt; endl;
AliveFile.close();
} 
return 0;
</code></pre>

<p>But when I get the drive letter from the console input and save the path to a string and pass that to AliveFile.open it doesn't work:</p>

<pre><code>string DriveLetter;
cout &lt;&lt; "What is the drive letter for the drive you want to keep awake?" &lt;&lt; endl;
getline(cin, DriveLetter);
cin.clear();
string Path;
Path = "\"" + DriveLetter + ":\\alive.txt\"";
cout &lt;&lt; Path &lt;&lt; endl;

while (true)
{
Sleep(10000);
ofstream AliveFile;
AliveFile.open ( Path );
AliveFile &lt;&lt; "alive" &lt;&lt; endl;
AliveFile.close();
} 
return 0;
</code></pre>

<p>The path comes out fine when i cout &lt;&lt; Path so I do not understand why AliveFile.open(Path) does not work.</p>
