问题
I followed the instructions given in this thread for creating a file in a sub-directory.
ofstream forceFile;
forceFile.open(".\\output_files\\error_log.csv", ios::out | ios::app);
forceFile << "stuff" << "\r\n";
forceFile.close();
But now I have files, with size, in the base directory that cannot be opened and are named
.\output_files\error_log.txt
if I double click the file, I am told the file cannot be found and told to try a different path. if I open with notepad++ I am asked if I want to create the file. The an empty file is created in .\output_files
The files are created by my university linux cluster in the university shared server space, then I am viewing the file through an AFS link on my windows laptop.
回答1:
The problem is that you are using backslashes, not slashes.
The path component delimiter on UNIXes is /
, not \
.
And because /
is not particularly special in a C string, you do not need to escape it with a backslash. So: not \\
, not \/
and certainly not //
.
来源:https://stackoverflow.com/questions/23277681/created-file-in-subdirectory-but-cannot-open-file