How to use fstream objects with relative path?

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

    The behaviour is OS specific. Therefore, the best way to handle this IMHO is to make it somebody else's problem. Read the path to the file to open as a string from the user (e.g: command line argument, config file, env variable etc..) then pass that string directly to the constructor of fstream. Document that this is how your program behaves.

    I wrote more about path manipulation here: https://stackoverflow.com/a/40980510/2345997

提交回复
热议问题