created file in subdirectory but cannot open file

我的未来我决定 提交于 2019-12-11 19:47:47

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!