How to use fstream objects with relative path?

前端 未结 7 1934
终归单人心
终归单人心 2020-12-03 02:53

Do I always have to specify absolute path for objects instantiated from std::fstream class? In other words, is there a way to specify just relative path to them

7条回答
  •  一个人的身影
    2020-12-03 03:19

    On linux also:

    // main.cpp
    int main() {
        ifstream myFile("../Folder/readme.txt");
        // ...
    }
    

    Assuming the folder structure is something like this:

    /usr/Douments/dev/MyProject/main.cpp /usr/Documents/dev/MyProject/Folder/readme.txt

提交回复
热议问题