gpt4 book ai didi

C++ - 如何将 JSON 写回文件

转载 作者:行者123 更新时间:2023-11-27 23:59:46 25 4
gpt4 key购买 nike

我正在使用来自 https://github.com/nlohmann/json 的库
我需要将我的 JSON 写入文件,但我在文档中找不到任何相关内容。
谁能帮忙?

最佳答案

您可以像这样将 JSON 值 j 写入文件:

std::ofstream o("output.json");
o << j << std::endl;

如果你想美化输出,使用:

std::ofstream o("pretty.json");
o << std::setw(4) << j << std::endl;

关于C++ - 如何将 JSON 写回文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40029100/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com