Newbie Question.........

Started by
13 comments, last by Android 13 22 years, 5 months ago
I know this may sound dumb, but how do you save in C++. I looked in my books, but I cant find out how to save in it. Im relativley new to it, so i was hopeing you could help me. Thank you. Mess with the best, Die like the rest!!
Mess with the best,Die like the rest!!
Advertisement
C++ source files are just normal text files. You can make and edit them in any ANSI text editor.

--Buzzy
No, I mean thank you for answering, but what I ment was how do you code C++ to save. Like what like of code would I use.

Mess with the best,
Die like the rest!!
Mess with the best,Die like the rest!!
Look for open/read/write/close, or fopen/fread/fwrite/fprintf/fclose.

Some of the parameters are tricky (ensuring you set the "create" bit for a new file in the open command, for instance) so read the docs carefully.


if you mean,
"how do i save a bunch of data so that the program can get the data the next time it runs?"

then, what you have to do is save your data to a textfile or to a data(binary) file.

check out "fstream"
or "file i/o" in any c++ book
or search for tutorials on these online
What im wondering is like if you were in a program, and you wanted to save your progress. What line/lines of code would you use to let the user save thier progress. I dont know if it helps but im compialing in Dev C++.

Mess with the best,
Die like the rest!!
Mess with the best,Die like the rest!!
What you looking for has the potential of being extremely complex or very simple. It all depends on your needs. What you are asking is "How do I save a game state?" This depends on a lot of different factors. The best advice I could give you is to first learn fundamentals of file i/o with simple Hello World type programs that save to disk in various formats. Once you see the many different ways you can save actual data itself coupled with object data structure persistance you''ll understand why this question is a can of worms best left un-opened for now till you''re absolutely ready for those concepts.

YAP-YFIO

-deadlinegrunt

~deadlinegrunt

It''s not compiler dependant. The concept of saving is storing your data into another file (such as player''s position, player''s score, etc) and then "loading" a saved game involves reconstructing the game with the data in the file that was saved to.

Hope that helps.

If you can read this, All your base are belong to us!
I know some C++, Ill give you an ecample of the things i know, here is my first game. Warning: Very Basic.


//Monster Fighter is a basic battle program to
//Practice C++

#include

int userLvl;
int monsterLvl;
int f = 0;
int main()
{
//white space, specification term to center text here

cout << "Welcome to Monster Fighter V 1.0 created by: Adam Osterkamp.\n";


cout << "Please enter your Power Level 1,000 - 10,000: ";
cin >> userLvl;

begin:
cout << "Please choose a Monster Level between 1-5: ";
cin >> monsterLvl;

if (monsterLvl < 1 || monsterLvl > 5)
{
cout << "You cant do that! Restart the Program Fool!";
cin.ignore(256,''\n'');
cout<<"press enter to continue..."< cin.get();
goto begin;
}

if (monsterLvl == 1)
{
monsterLvl *= 1000;
}

if (monsterLvl == 2)
{
monsterLvl *= 1000;
}

if (monsterLvl == 3)
{
monsterLvl *= 2000;
}

if (monsterLvl == 4)
{
monsterLvl *= 2500;
}

if (monsterLvl == 5)
{
monsterLvl *= 3000;
}

while (f == 0)
{
if (monsterLvl < userLvl)
{
cout << "WOW! Your powerfull! You beat the Monster, Good Job!!";
cin.ignore(256,''\n'');
cout<<"press enter to continue..."< cin.get();
}

if (monsterLvl > userLvl)
{
cout << "HA! Your weak, get stronger and try again!";
cin.ignore(256,''\n'');
cout<<"press enter to continue..."< cin.get();
}
f++;
}

return 0;
}

There is a small bug, but it runs the way it is supposed to, unless user error occers, which im fixing. But lets say, if you lost this battle you get 30 on your PL and if you win you get 60. Now i know i would have to add some code in there to do this but then if i wanted to save that info, so later i could ask for your character, how would i do that?

Mess with the best,
Die like the rest!!
Mess with the best,Die like the rest!!
Hey, Android, I think I saw you at MGS2 board and www.gamefaqs.com???
Say, you have any good link for MGS2 screenshot?
Nothing is impossible if you don''t take it seriously...And nothing is possible if you take it seriously.

This topic is closed to new replies.

Advertisement