将一组数组保存到文件并返回到 C++ 的简单方法是什么?
我一直在寻找一种使用 C++ 的简单方法来将一组变量(在本例中为一组双数组)保存到文件中,然后加载所述文件并获取变量集。
我读到的大多数方法都意味着将所有变量集中到一个数组中,或者(更糟糕的是)编写一个自定义类来手动逐个字符地读取和写入,所有这些都是不切实际的,因为数组将具有可变长度。
有我可以使用的类或库吗? (我问这个问题的事实意味着,是的,这是我第一次必须处理 C++ 中的文件。)
I've been searching for an easy way with C++ to save a set of variables (in this case, a set of double arrays) to a file, and later load said file and get the set of variables.
Most of the ways that I've read about imply to lump all of the variables into a single array, or (even worse) write a custom class that reads and writes character by character, manually, all of which is impractical since the arrays will have variable length.
Is there a class or library that I could use? (The fact that I am asking this question means that, yes, it's one of the first times I have to deal with files in C++.)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
协议缓冲区可能有助于:
protobuf
The protocol buffers may help:
protobuf
Boost 序列化库是一种选择。
The boost serialization library is one option.