• Advertisement

Archived

This topic is now archived and is closed to further replies.

saving

This topic is 5526 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

can someone suggest a tutorial in that if someone hits CTRL + S will bring up the whole "windows Save box" and it will save to a text file and CTRL + L will bring up the whole "windows Load box" and it will load from a text file? shuv-it

Share this post


Link to post
Share on other sites
Advertisement
anyone

all i need is how to write and load out of text .txt (or .fqs files in my case) files

shuv-it

Share this post


Link to post
Share on other sites
Check out...

http://www.planetsourcecode.com

There might be something there.

- Rob Loach
OverTech Technologies
-----------
"Life moves pretty fast. If you don''t stop and look around once in awhile, you could miss it."
- Ferris Bueller

Share this post


Link to post
Share on other sites
OPENFILENAME, GetOpenFileName and GetSaveFileName should get you started.

Share this post


Link to post
Share on other sites
To repeat the advice others have given you: SLOW DOWN. You are trying to skip to the ''fun'' before you''ve learned the basics of program design. Recent queries you have made involved a console program with everything defined in main() and very linear structure. You need to at least master THAT before you even think about graphics and Win32 API questions.

Share this post


Link to post
Share on other sites
I wait, I know this game, guess the posters age.
Judging by the name "craphead", the fact that it is listed as being from "Toys R Us", and the signature of "shuv-it" I would have to say that the aptly named "craphead" is no more than 12 and is still too afraid to say dirty words when noone can hear it.
[edit]
whoa, checking back through scheisekopfs profile it gives it's age at 11.
[/edit]

[edited by - capn_midnight on December 3, 2002 1:52:54 AM]

Share this post


Link to post
Share on other sites
He isn''t that bad. He has been here for a while and is showing an effort to learn, hasn''t given up, and he hasn''t been overly annoying.

Although you probably should email Dave and ask him really nicely to change your username if you want to keep your account, since I don''t think you''re going to want to be associated with it if you plan to stick around for a long period of time.

Share this post


Link to post
Share on other sites
Not exactly what you asked for, but anyway . . .


  
#include <iostream>

#include <fstream>

using namespace std;

class Character
{
protected:
// Variables

string name;
int hitpoints, gold;

public:
// Default constructor.

Character(void): name("noname"), hitpoints(100), gold(0)
{}

// Displays a characters stats

void GetStats(void)
{
cout << "Character " << name << ":" << endl;
cout << "Hitpoints: " << hitpoints << endl;
cout << "Gold: $" << gold << endl;
}

// Sets a characters stats

void SetStats(void)
{
cout << "Name: ";
cin >> name;
cout << "Hitpoints: ";
cin >> hitpoints;
cout << "Gold: $";
cin >> gold;
}

// Saves a character to a file.

void Save(void)
{
string filename;
cout << "File to save to: ";
cin >> filename;
fstream file(filename.c_str(), fstream::out | fstream::trunc);

if(!file.good())
{
cout << "Error opening " << filename << "." << endl;
return;
}

file << *this;
if(!file.good())
cout << "Error writing to " << filename << "." << endl;
}

// Loads a character from a file.

void Load(void)
{
string filename;
cout << "File to load: ";
cin >> filename;
fstream file(filename.c_str(), fstream::in);

if(!file.good())
{
cout << "Error opening " << filename << "." << endl;
return;
}

file >> *this;
if(!file.good())
cout << "Error reading from " << filename << "." << endl;
}

// For reading a player from a stream

friend istream & operator >> (istream &stream, Character &player)
{
stream >> player.name >> player.hitpoints >> player.gold;
return stream;
}

// For writing a player to a stream

friend ostream & operator << (ostream &stream, const Character &player)
{
stream << player.name << '' '' << player.hitpoints << '' '' << player.gold << endl;
return stream;
}
};

int main(void)
{
Character dude;

int choice;

while(true)
{
cout << "Current character: " << endl;
cout << "-----------------------" << endl;
dude.GetStats();
cout << "-----------------------" << endl;
cout << "What do you want to do:" << endl
<< " 1 - Create a character" << endl
<< " 2 - Load a character" << endl
<< " 3 - Save a character" << endl
<< " 4 - Quit" << endl;
cin >> choice;

switch(choice)
{
case 1:
dude.SetStats();
continue;

case 2:
dude.Load();
continue;

case 3:
dude.Save();
continue;

case 4:
break;

default:
cout << "Unknown option." << endl;
continue;
}

break;
}
}


There are probably some exceptions I''m supposed to catch but I don''t care. Just cross your fingers and hope it works.

iostream library reference from www.cplusplus.com

Share this post


Link to post
Share on other sites
quote:
Original post by capn_midnight
I wait, I know this game, guess the posters age.
Judging by the name "craphead", the fact that it is listed as being from "Toys R Us", and the signature of "shuv-it" I would have to say that the aptly named "craphead" is no more than 12 and is still too afraid to say dirty words when noone can hear it.
[edit]
whoa, checking back through scheisekopfs profile it gives it's age at 11.
[/edit]

[edited by - capn_midnight on December 3, 2002 1:52:54 AM]


1. I don't see why age should determine whether or not we help someone.

2. Your post hardly oozes maturity


Lektrix
[ Google || ACCU || BarrysWorld || E-Mail Me ]

[edited by - Lektrix on December 3, 2002 4:28:18 PM]

Share this post


Link to post
Share on other sites
Maybe one of these fstream tutorials can help

here

here

EDIT: this is about as basic a files get so if they dont make sence try learning more first.

also file input/output isn't that interesting untill you know enough to do something with it.

Good luck

[edited by - googlyeyes on December 3, 2002 6:34:00 PM]

Share this post


Link to post
Share on other sites
LOL,
k, I konw what he''s talking about.
HAs anyone played RollerCoaster Tycoon 2?
And all you guys should know that Windows file loading thing which you get in programs like Winamp and Paint.

What he means is how to make such a thing IN-GAME like in RollerCoaser Tycoon 2... Or maybe not ingame...

.lick

Share this post


Link to post
Share on other sites

  • Advertisement