类数据存储C ++ [英] class data storage c++

查看:61
本文介绍了类数据存储C ++的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,我正在寻找一种方法来保存我正在开发的游戏的类数据,并且需要将其另存为savegame的二进制文件和用户设置的文本文件.
我确实在Google上找到了一篇有关保存二进制文件的文章,但找不到了,
预先感谢您的回答.

Hi all, I''m looking for a way to save class data for a game I''m developing and need to save it as a binary file for a savegame and a text file for user settings.
I did find an article on Google about saving binary files but couldn''t find it again,
Thanks in advance for the answers.

推荐答案

为什么不将其另存为XML?这是一篇可以帮助您保存/加载简单xml数据文件的文章:

XML应用程序配置文件类 [
Why not just save it as XML? Here''s an article that will help you save/load a simple xml data file:

XML Application Profile Class[^]


如果您要保存任何内容,那么流就是答案-实现:

If you want to save anything then streams are the answer - implement:

std::ostream &operator<<( std::ostream &, const object & );


和:


and:

std::istream &operator>>( std::istream &, const object & );


为您的课堂和剪发,剪下,鲍勃的yer阿姨.

这将有多困难取决于您如何构造数据.

干杯,

Ash


for your class and snip, snip, Bob''s yer Aunty.

How difficult this will be depends on how you''ve structured your data.

Cheers,

Ash


我建​​议阅读以下系列文章:序列化入门-第1部分 [ ^ ].当然,这与MFC有关,但至少您可以学习一些有趣的东西,并根据自己的情况进行调整.
正如约翰已经建议的那样,我将使用XML保存用户设置.但仅对于设置而言,您的游戏数据应保存为二进制文件.
I suggest this series of article: A serialization primer - Part 1[^]. Of course, this is related to MFC but at least you can learn some interesting things and adapt those to your own case.
As John already suggested, I would use XML to save the user settings. But only for the settings, the data of your game should be saved as binary file.


这篇关于类数据存储C ++的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆