Re: [Dev-C++] Loading variables from files [C++]
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Derek C. <de...@ci...> - 2008-04-28 10:08:30
|
A good way is to add serialise operators to the class:
ostream& hero::operator>>(ostream& stream)
{
mapid >> stream;
posx >> stream;
posy >> stream;
return stream;
}
istream& hero::operator <<(istream& stream)
{
mapid << stream:
posx << stream;
posy << stream;
return stream;
}
On Mon, Apr 28, 2008 at 6:40 AM, Samuel Hulley <tal...@gm...> wrote:
> Hi,
> I am attempting to load variables from files but im not sure what
> todo because the variables are different types and sizes.
> Here is the source:
>
> #pragma once
> #include <fstream>
> using namespace std;
>
> class hero
> {
> public:
> void setname(string first, string last)
> {
> fname = first;
> lname = last;
> return;
> }
>
> void setmap(int mp)
> {
> mapid = mp;
> return;
> }
>
> void setpos(int x, int y)
> {
> posx = x;
> posy = y;
> return;
> }
>
> void setmapx(int x)
> {
> posx = x;
> return;
> }
>
> void setmapy(int y)
> {
> posy = y;
> return;
> }
>
> int getmap()
> {
> return mapid;
> }
>
> int getmapx()
> {
> return posx;
> }
>
> int getmapy()
> {
> return posy;
> }
>
> void loadinfo()
> {
> // This is where I will load the config.
> }
>
> private:
> // Map variables.
> int mapid;
> int posx;
> int posy;
> };
>
> Yours Truly
> Samuel Hulley.
>
> -------------------------------------------------------------------------
> This SF.net email is sponsored by the 2008 JavaOne(SM) Conference
> Don't miss this year's exciting event. There's still time to save $100.
> Use priority code J8TL2D2.
> http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
> _______________________________________________
> Dev-cpp-users mailing list
> Dev...@li...
> TO UNSUBSCRIBE: http://www23.brinkster.com/noicys/devcpp/ub.htm
> https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
>
|