【问题标题】:Append string to the end of file using boost::filesystem使用 boost::filesystem 将字符串附加到文件末尾
【发布时间】:2014-01-23 13:28:44
【问题描述】:

使用较新的 boost(例如 1.55)我可以将一个字符串附加到路径的末尾,如下所示:

 fs::path binShaderPath("somedir/somefile.bin");
     binShaderPath  +="xxx";

在我的情况下,我使用 Boost 1.49,它不会出现这种过载。解决方法是什么?

对于那些将指向我的人this 回答:我不想附加目录或文件,只是在文件末尾添加一些任意字符。

更新:

目前我想出的解决方法是:

             std::string copySrt = binShaderPath.string();
             copySrt.append(".xxx");
             binShaderPath = fs::path(copySrt);

效率不高,字符串复制等,但我没有找到其他方法。

【问题讨论】:

  • 有类似fs::path(binShaderPath.file_string() + "xxx") 的帮助吗?
  • 没有file_string()。有.string() 是const
  • 嗯,好吧 - 虽然 1.49 会使用旧的文件系统接口... constness 在我的 sn-p 中会是一个问题,因为它无论如何都会复制构造

标签: c++ boost


【解决方案1】:

您可以重载 operator+= 以获得所需的结果

【讨论】:

    猜你喜欢
    • 2022-12-11
    • 2020-08-19
    • 2014-03-06
    • 2015-02-02
    • 2017-09-29
    • 2020-12-19
    • 2017-06-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多