hmm few more questions, if u have many save files how do you get your program to say look in a directory and then make a list of all the files in that directory and then allow you to load them?
hmm few more questions, if u have many save files how do you get your program to say look in a directory and then make a list of all the files in that directory and then allow you to load them?
There is a way to read a directory, but you'll have too look for the tutorial yourself, but I personally open two files on save time (one if the save already exists) one has a list of all the saves, the other is the actual save file. Lame way of doing this, but it works.
Well if I can't find a tutorial I'll keep that in mind, thanks again.Originally posted by Dark Nemesis
There is a way to read a directory, but you'll have too look for the tutorial yourself, but I personally open two files on save time (one if the save already exists) one has a list of all the saves, the other is the actual save file. Lame way of doing this, but it works.
Why do you have multiple save files? Why dont you just save all the data onto one save file? It would look like this:
Should look like this once compiled:Code:#include <iostream.h> #include <fstream.h> int main() { int hp=100, exp=2000, lvl=10; ofstream save("save.ini"); save << hp << "\n" << exp << "\n" >> lvl; save.close(); hp=0;exp=0;lvl=0; ifstream read("save.ini"); read>>hp; read>>exp; read>>lvl; read.close(); cout<<hp<<" "<<exp<<" "<<lvl<<endl; system("PAUSE"); return 0; }
Code:100 2000 10 Press any key to continue...
Hope I helped
Last edited by Newbie Magic; 11-22-2003 at 03:30 PM.
Here is a program that I made a little while ago using that save method (it is saved in hex so it may look different):
LevelUp.zip
You shouldn't use system("CLS") to clear the screen, go to the C++ board and look at Clearing Text if you want.
Also, instead of:
Use:Code:using namepsace std;
Probably other using std's but that's all I've had to use in my simple programs...Code:using std::cin; using std::cout; using std::endl; ...
Oh, yeah. Instead of:
Use:Code:#include <iostream.h> //Deprecated header.
Edit: Oh! Oops! Someone already said about the deprecated/correct headers!Code:#include <iostream> //Correct header.
Last edited by SirCrono6; 11-27-2003 at 12:20 PM.
From C to shining C++!
Great graphics, sounds, algorithms, AI, pathfinding, visual effects, cutscenes, etc., etc. do NOT make a good game.
- Bubba
IDE and Compiler - Code::Blocks with MinGW
Operating System - Windows XP Professional x64 Edition
what s the diff between using namespace std and the deprecated header i dont get it
It's all part of programming better, and to the standard...
From C to shining C++!
Great graphics, sounds, algorithms, AI, pathfinding, visual effects, cutscenes, etc., etc. do NOT make a good game.
- Bubba
IDE and Compiler - Code::Blocks with MinGW
Operating System - Windows XP Professional x64 Edition
If you did this just a little after learning C++ then what did you use to learn? Books? Online tutorials? If so, which one did you use? I can do a little C++ but don't understand it that much. It looks like you got it fine and I want to make stuff like that too. So what did you use, or what would you reccomend for me to learn C++ better?
From C to shining C++!
Great graphics, sounds, algorithms, AI, pathfinding, visual effects, cutscenes, etc., etc. do NOT make a good game.
- Bubba
IDE and Compiler - Code::Blocks with MinGW
Operating System - Windows XP Professional x64 Edition