I need save a file in a different location but the file is not a default name that will be put in there it is a name that the user will assign to the document: (This is not the all the program it is just part of it)
string file;
string txt = ".txt";
ofstream outfile;
cout << "Please, enter the name for your output file: ";
getline(cin, file);
file += txt;
outfile.open("C:/Users/contr/Documents/Custom Office Templates/file.c_str()");
//Here is were the file wont be save as the
//user was ask for it will will be file.c_str()
outfile.close();
cout << "\nProccessing your request\n";
cout << "The program has saved the file as: "
<< file << endl << endl;
You have to concatenate the value contained in file to the path you want it to go into.
The easiest way that I can think of is to create a new string to contain the path and the append the file name. Then use the new string to open the file.