Question

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.

Was it helpful?

Solution

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 //.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top