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?
Printable View
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.Quote:
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 ;)
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
That's a cool program :D. Good job on the lvl up. :)
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! :DCode:#include <iostream> //Correct header.
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...
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?