Save?
How do you save stuff for later use in C++? Like saving game files? I have a game that''s really long, and people are most likely going to quit during it. Any help REQUIRED!
Try reading the manual: http://www.cplusplus.com/ref/. There''s information on that page for both C and C++ style file I/O (and examples of at least the C style).
The easiest way to find out what it will do is to go and read it.
GSACP: GameDev Society Against Crap PostingTo join: Put these lines in your signature and don't post crap!
Here's the source for saving and loading from my RPG. Note: I hope you know all about voids.
[edited by - Quantrizi on April 5, 2002 12:02:48 PM]
void save(){ ofstream gamedata; //Opens data.rpg and saves information. gamedata.open("data.rpg",ios::out); if(gamedata) { gamedata << hp << endl; gamedata << maxhp << endl; gamedata << mp << endl; gamedata << maxmp << endl; gamedata << magic << endl; gamedata << magicresist << endl; gamedata << exp << endl; gamedata << lvl << endl; gamedata << money << endl; gamedata << potionsplayerhas << endl; gamedata << ethersplayerhas << endl; } else cout<<"Error opening file data.rpg.\n"; gamedata.close(); decision.yesno; if(answer) { town(); }}void load(){ ifstream gamedatain; //Opens File "data.rpg" and retreives info gamedatain.open("data.rpg",ios::in | ios::binary | ios::nocreate); if(gamedatain) gamedatain >> hp >> maxhp >> mp >> maxmp >> magic >> magicresist >> exp >> lvl >> money >> potionsplayerhas >> ethersplayerhas; //Closes Save.txt gamedatain.close();//Goes back to town town();}void stats(){ int exptonextlevel=0; exptonextlevel = (lvl * 1000) - exp; //Display Current Status to User lvl = exp / 1000 + 1; cout << endl; cout << "Here are your current Stats:\n"; cout << "----------------------------\n"; cout << "HP: " << hp << "\\" << maxhp << endl; cout << "MP: " << mp << "\\" << maxmp << endl; cout << "Mag: " << magic << endl; cout << "Mag R: " << magicresist << endl; cout << "Gil: " << money << endl; cout << "Lvl: " << lvl << endl; cout << "EXP: " << exp << endl; cout << "EXP to Next Level: " << exptonextlevel << endl; cout << "Pos: " << potionsplayerhas << endl; cout << "Ets: " << ethersplayerhas << endl; cout << "-----------------------------\n\n";};
[edited by - Quantrizi on April 5, 2002 12:02:48 PM]
How do you know which file it''s going into? And how do you initialize that file in the first place?
front page of gamedev.net
"in the news"
Friday, April 05, 2002:
File I/O in C++
read the article:
http://www.cpp-home.com/FileIO_tutorial.php
then go buy a learn C++ book and read the chapters on file I/O should the above article not be enough
-me
p.s. I/O means input/output or in the case of files: reading/writing
[edited by - Palidine on April 5, 2002 5:27:09 PM]
"in the news"
Friday, April 05, 2002:
File I/O in C++
read the article:
http://www.cpp-home.com/FileIO_tutorial.php
then go buy a learn C++ book and read the chapters on file I/O should the above article not be enough
-me
p.s. I/O means input/output or in the case of files: reading/writing
[edited by - Palidine on April 5, 2002 5:27:09 PM]
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement