Im trying to rename my file to the new name that the user has shown but i get a error. here is the code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
int StoreDatabase()
{
string FileName;
LetterByLetter Print;
ofstream StoreInDatabase("Main_Database.txt");
system("cls");
DisplayText = "What would you like to name the new text file?";
Print.Text();
cin >> FileName;
string NewName;
string extention;
extention = ".txt";
NewName = FileName + extention;
rename("Main_Database.txt",NewName);
system("PAUSE");
}
std::rename takes c strings as argument so you have to convert the std::string to a c string by using the c_str() member function rename("Main_Database.txt",NewName.c_str());
Alright so I did some messing around and asking around. Make sure your stream is closed before you attempt to rename, and also make sure the file is in the right directory.
So for you, before you call rename(), call StoreInDatabase.close()