Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Android 13

Newbie Question.........

This topic is 6106 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

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!!

Share this post


Link to post
Share on other sites
Advertisement
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!!

Share this post


Link to post
Share on other sites
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.


Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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!!

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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!

Share this post


Link to post
Share on other sites
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!!

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!