How to use fstream objects with relative path?

前端 未结 7 1909
终归单人心
终归单人心 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:11

    Say you have a src folder directly under your project directory and the src folder contains another tmp_folder folder which contains a txt file named readMe.txt. So the txt file can be read in this way

    std::ifstream fin("../src/tmp_folder/readMe.txt");
    

提交回复
热议问题