File output

In my program it requires a file to be saved to a folder. Since i use this folder so often i want to know how to make a pre-set file path. When i try this code(This is just a piece of the whole thing), It won't output the file.
cout<<"Type file name"<<endl;
	name = "C:\sharing folder\"" + name; 
	ofstream fout;,ios::app);

Also, i'm wondering why it requires two apostrophes to be correct on the 3rd line.
Last edited on
What is the error ?

As for the 2 apostrophes, it's because \ is an escape character, ie it's used to indicate a non-writable character.
If that's a problem, you can also write "C:/sharing folder/"
name = "C:\\sharing folder\\" + name;

use double '\' to represent an actual backslash character. Otherwise the compiler tries to interpret the '\' together with the next character, for example '\n' or '\0' etc.

See "escape codes" under the heading "Character and string literals" here:
Last edited on
Thank Chervil, it's working now.
Topic archived. No new replies allowed.