【问题标题】:How to open a file in boost如何在boost中打开文件
【发布时间】:2014-04-19 21:02:40
【问题描述】:

我对使用 c++ 的 boost 库比较陌生,我想知道如何使用它打开文件。我的目标是从 json 文件中读取,但我不知道如何打开该文件。

在 c++ 中,你可以这样做

int main () {
  ofstream myfile;
  myfile.open ("example.txt");
  myfile << "Writing this to a file.\n";
  myfile.close();
  return 0;
}

但是如何使用 boost 来做到这一点?

【问题讨论】:

标签: c++ boost


【解决方案1】:

您可以使用boost::filesystem::ifstream(与boost::filesystem::path 实例一起使用)或简单地使用std::ifstream 来读取文件。

实际代码很大程度上取决于您的具体用例。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-07-04
    • 2022-01-04
    • 2019-06-02
    • 2017-01-11
    • 2018-03-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多