Hi..
can I specify a location to save my file using ofstream?
e.g.
std::ofstream SAVEFILE ("filename.txt");// 'filename.txt' will be saved in my cpp files directory. My question is can I specify a different directory??
sure, you can write a relative and an absolute path, whatever you want.
notice that you'll have to make sure you use the right slash (backslash for directories in windows, forwardslash for unix based systems)
I'll use a define for the slash in this example because I don't know if you use linux or windows.
Note: to have 1 backslash you need 2 backslashes (1 for escaping the other one)
std::ofstream file3("~/file.txt") // creates file in home-folder (linux)
The tilde (~) is usually expanded by the shell, but the shell is not involved here so it will not work. If you have a directory named "~" in the current working directory it will create the file there.