i just want to ask

I am beginner in C++, I just want to ask, I don't know how to do an automatic saved program. Example i made a hangman with a score then when i exit the game
and open it again i want to still see that high score. Something like that. Please help thnks
The usual method is to keep a little data file (a simple text file would do nicely) that lists the top n high-scores and player names and whatever else you want. An example file (with five high-scores) might look something like this:
1
2
3
4
5
23400 Snoopy
3600 Linus VanDerPelt
1200 Lucy VanDerPelt
900 Sally Brown
100 Charlie Brown

In your code, every time a game ends, update your list of high-scores (that you have in memory) and write them to the high-scores file (on disk).

When the game starts, initialize your list of high-scores to zero, no-name, etc., then look for the file on disk and, if it is there, read them into the list.

Hope this helps.

Oh yeah, almost forgot:
When reading strings from a text file, use getline(), not >>. So to read a score might be:
1
2
3
4
5
6
7
8
9
10
  ifstream f( 'highscores.txt' );
  string name;
  for (
    int i = 0; 
    f >> high_scores[ i ].score;
    i++)
  {
    f.get(); // skip the space
    getline( f, high_scores[ i ].name );
  }

This example is completely devoid of error checking just to make things simple. Here it is with error checking:
1
2
3
4
5
6
7
8
9
10
  ifstream f( 'highscores.txt' );
  string name;
  for (
    int i = 0;
    (i < (sizeof( high_scores ) / sizeof( high_scores[ 0 ] ))) and (f >> high_scores[ i ].score);
    i++)
  {
    f.get(); // skip the space
    getline( f, high_scores[ i ].name );
  }

The sizeof/sizeof trick is to handle whatever the size of the array you create without allowing overflow.

Hope this helps.
Topic archived. No new replies allowed.