How to build a full path string (safely) from separate strings?

后端 未结 7 1292
失恋的感觉
失恋的感觉 2020-12-08 12:34

Does C++ have any equivalent to python\'s function os.path.join? Basically, I\'m looking for something that combines two (or more) parts of a file path so that

相关标签:
7条回答
  • 2020-12-08 13:28

    With C++11 and Qt you can do this:

    QString join(const QString& v) {
        return v;
    }
    
    template<typename... Args>
    QString join(const QString& first, Args... args) {
        return QDir(first).filePath(join(args...));
    }
    

    Usage:

    QString path = join("/tmp", "dir", "file"); // /tmp/dir/file
    
    0 讨论(0)
提交回复
热议问题