Sign in to follow this  

[C++] Save and load system

This topic is 3627 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 somebody help me, it'l save but not load!
void save()
{
	ofstream out("SAVE.txt");
	
	if (!out) {
             cout << "[ERROR]" << endl;
             cin.get();
             }
             
	out << sword << shield  << cuirass << greaves;	
	out << gold << boots << game_running << sword_skill;
	out << axe_skill << blunt_skill << room << player_stats[0];
    out << player_stats[2] << player_stats[3] << player_stats[4];
    out << player_race << player_name;
	out.close();				//close it
	cout << "Game Saved" << endl << endl;
}

void load()
{
    ifstream in("SAVE.txt");
    
	if (!in) {
             cout << "[ERROR]" << endl;
             cin.get();
             }
             
	in >> sword >> shield  >> cuirass >> greaves >> gold >> boots >> game_running >> sword_skill >> axe_skill >> blunt_skill >> room >> player_stats[0] >> player_stats[1] >> player_stats[2] >> player_stats[3] >> player_race >> player_name;
   	in.close();			
	cout << "Game Loaded" << endl << endl;
}

Share this post


Link to post
Share on other sites
Maybe I'm just not seeing it, but let's see how this is called. Seems like the problem would be in the function itself, but let's just see it.

Also, what bug testing have you done? Have you discovered anything that might help our diagnosis?

Have you checked that the file was saved, or are you taking your program's word for it?

Share this post


Link to post
Share on other sites
Post what is acctually being written to the file.

If I were to guess though you are writing integers and strings to the file and probobly without spaces inbetween. When you try to read it back in it does not know what to do because it is a big mess of numbers and characters.

Share this post


Link to post
Share on other sites
Here's my shoe size, my waist size, and the amount of change in my pocket (in cents): 1131138. Easy to write, hard to read.

Share this post


Link to post
Share on other sites
It is called using
if (command == "save")
save();
else if (command == "load")
load();

I have checked that it does create a file, and it does look like Sneftel's post:
00002001000581030HumanGary

Share this post


Link to post
Share on other sites

This topic is 3627 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this