How to use fstream objects with relative path?

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

    If you have an .exe file running from C:\Users\Me and you want to write a file to C:\Users\Me\You\text.txt, then all what you need to do is to add the current path operator ., so:

    std::ifstream ifs(".\\you\\myfile.txt");
    

    will work

提交回复
热议问题