保存对象 [英] Saving Objects

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

问题描述

我正在写一个游戏,我所有的游戏部分都存储在一个单独的

向量句柄中。我有基本的东西,我可以读写char

和数字文件,但我正在尝试做更复杂的事情。我想要保存我需要保存的数据,我可以填写一些

保存必要的数据。


Vector->片段句柄 - 指向片段。如何将这些数据保存到文件中?
我一直在对一些

网站进行一些研究: http://www.angelfire.com/country/aldev0/cpphowto/

cpp_BinaryFileIO.html


我似乎得到了一些东西保存。到目前为止,在我的手柄中,我有一个保存功能,可以保存这些碎片。这里

是我要​​保存的数据:


班级单位{

受保护:


coord loc;

coord currentLoc;

graphics * gr;

tbox * combatBox;

std :: vector< color> colors;


float attack;

float dattack;

浮动防御;


更多数字......


以下是我的开始:

void unit :: write(std :: fstream& ; f){


f.write((char *)& loc,sizeof(loc));

f.write((char *) & colors,sizeof(colors));


我是以正确还是错误的方式进行的?

I am writing a game and all my game pieces are stored in a single
vector of piece handles. I have the basics I can read and write char
and number files but I am trying to do comthing more complicated. I
am trying to save the data I need to save and I can fill in some when
the necessary data is saved.

Vector->piece handle -pointer to the pieces. How do I go about
saving that data into a file. I have been doing some research to some
sites: http://www.angelfire.com/country/aldev0/cpphowto/
cpp_BinaryFileIO.html

I seem to get somthing to save. So far in my handle for the pieces I
have a save function that will have the pieces save themselvs. Here
is the data I want to save:

class unit{
protected:

coord loc;
coord currentLoc;
graphics * gr;
tbox * combatBox;
std::vector<color>colors;

float attack;
float dattack;
float defence;

More numbers...

Here is how I am starting:
void unit::write(std::fstream& f){

f.write((char*)&loc, sizeof (loc));
f.write((char*)&colors, sizeof (colors));

Am I going about it the right or wrong way?

推荐答案

1月31日上午11:56,JoeC < enki ... @ yahoo.comwrote:
On Jan 31, 11:56 am, "JoeC" <enki...@yahoo.comwrote:

我正在写一个游戏,我所有的游戏部分都存储在一个

矢量的片句柄。我有基本的东西,我可以读写char

和数字文件,但我正在尝试做更复杂的事情。我想要保存我需要保存的数据,我可以填写一些

保存必要的数据。


Vector->片段句柄 - 指向片段。如何将这些数据保存到文件中?
我一直在对一些

网站进行一些研究: http://www.angelfire.com/country/aldev0/cpphowto/

cpp_BinaryFileIO.html
I am writing a game and all my game pieces are stored in a single
vector of piece handles. I have the basics I can read and write char
and number files but I am trying to do comthing more complicated. I
am trying to save the data I need to save and I can fill in some when
the necessary data is saved.

Vector->piece handle -pointer to the pieces. How do I go about
saving that data into a file. I have been doing some research to some
sites: http://www.angelfire.com/country/aldev0/cpphowto/
cpp_BinaryFileIO.html



[snip] ]

[snip]


我是正确还是错误的方式?
Am I going about it the right or wrong way?



常见问题涵盖了这个主题:

http://www.parashift.com/c++-faq-lit...alization.html

祝你好运,


Tom


The FAQ covers this subject in depth:

http://www.parashift.com/c++-faq-lit...alization.html

Best regards,

Tom



1月31日,11: 21日上午,Thomas Tutone < Thomas8675 ... @ yahoo.comwrote:
On Jan 31, 11:21 am, "Thomas Tutone" <Thomas8675...@yahoo.comwrote:

1月31日上午11:56,JoeC < enki ... @ yahoo.comwrote:
On Jan 31, 11:56 am, "JoeC" <enki...@yahoo.comwrote:

我正在写游戏,我所有的游戏部分都存储在一个

矢量的片句柄。我有基本的东西,我可以读写char

和数字文件,但我正在尝试做更复杂的事情。我想要保存我需要保存的数据,我可以填写一些

保存必要的数据。
I am writing a game and all my game pieces are stored in a single
vector of piece handles. I have the basics I can read and write char
and number files but I am trying to do comthing more complicated. I
am trying to save the data I need to save and I can fill in some when
the necessary data is saved.


Vector-> piece handle -pointer to pieces。如何将这些数据保存到文件中?
我一直在对一些

网站进行一些研究: http://www.angelfire.com/country/aldev0/cpphowto/

cpp_BinaryFileIO.html
Vector->piece handle -pointer to the pieces. How do I go about
saving that data into a file. I have been doing some research to some
sites: http://www.angelfire.com/country/aldev0/cpphowto/
cpp_BinaryFileIO.html



[snip] ]


[snip]


我是正确还是错误的方式?
Am I going about it the right or wrong way?



常见问题涵盖了这个主题:

http://www.parashift.com/c++-faq-lit...alization.html

祝你好运,


Tom


The FAQ covers this subject in depth:

http://www.parashift.com/c++-faq-lit...alization.html

Best regards,

Tom



谢谢我在我的研究中找到了那个链接,但我是不知道怎么回事
应该对我有所帮助。我没有看到任何保存数据的exaples

那里。我创建了一个双人游戏,我想通过电子邮件系统创建一个游戏

,每次转动后,文件都会被保存

并发送给玩下一轮。我还有一个城市控制对象

以及每一方的分数。


如果我创建了一个文本文件,那会更好吗必要的

信息并将其发送并使用对象contsrtuctors和

设置批处理变量时程序加载备份。我已经在某种程度上使用了b $ b二手文件,这是我还没有做的事情

任何复杂的事情我想得到关于stratigies的建议

或至少是一个起点。

Thanks I did go to that link in my research but I am not sure how it
is supposed to help me. I don''t see any exaples of saving data
there. I created a two person game and I would like to create a play
by e-mail system where after each turn the file of pieces are saved
and sent off to play the next turn. I also have a city control object
and the number of points each side has.

Would it be better if I created a text file put in all the necessary
information and sent that off and use the objects contsrtuctors and
set the approate variables when the program is loaded back up. I have
used files to some extent already, it is that I have yet to do
anything complicated and I would like to get suggestions on stratigies
or at least a starting point.




JoeC napsal:

JoeC napsal:

我正在写一个游戏,我所有的游戏部分都存储在一个单独的

向量句柄中。我有基本的东西,我可以读写char

和数字文件,但我正在尝试做更复杂的事情。我想要保存我需要保存的数据,我可以填写一些

保存必要的数据。


Vector->片段句柄 - 指向片段。如何将这些数据保存到文件中?
我一直在对一些

网站进行一些研究: http://www.angelfire.com/country/aldev0/cpphowto/

cpp_BinaryFileIO.html


我似乎得到了一些东西保存。到目前为止,在我的手柄中,我有一个保存功能,可以保存这些碎片。这里

是我要​​保存的数据:


班级单位{

受保护:


coord loc;

coord currentLoc;

graphics * gr;

tbox * combatBox;

std :: vector< color> colors;


float attack;

float dattack;

浮动防御;


更多数字......


以下是我的开始:

void unit :: write(std :: fstream& ; f){


f.write((char *)& loc,sizeof(loc));

f.write((char *) & colors,sizeof(colors));


我是正确还是错误的方式?
I am writing a game and all my game pieces are stored in a single
vector of piece handles. I have the basics I can read and write char
and number files but I am trying to do comthing more complicated. I
am trying to save the data I need to save and I can fill in some when
the necessary data is saved.

Vector->piece handle -pointer to the pieces. How do I go about
saving that data into a file. I have been doing some research to some
sites: http://www.angelfire.com/country/aldev0/cpphowto/
cpp_BinaryFileIO.html

I seem to get somthing to save. So far in my handle for the pieces I
have a save function that will have the pieces save themselvs. Here
is the data I want to save:

class unit{
protected:

coord loc;
coord currentLoc;
graphics * gr;
tbox * combatBox;
std::vector<color>colors;

float attack;
float dattack;
float defence;

More numbers...

Here is how I am starting:
void unit::write(std::fstream& f){

f.write((char*)&loc, sizeof (loc));
f.write((char*)&colors, sizeof (colors));

Am I going about it the right or wrong way?



嗨。我建议你找一些XML库并将你的数据存储在

XML文件中。如果XML不是您可以使用的任何原因,请使用文本

文件。它可以为您节省大量阅读数据的时间,而且更便宜。

便携式。

Hi. I recommend you to find some XML library and store your data in
XML file. If XML is not for any reason what you can use, use text
file. It will save you lot of time with reading data and it is better
portable too.


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

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