Reader small image

You're reading from  Beginning C++ Game Programming. - Second Edition

Product typeBook
Published inOct 2019
Reading LevelIntermediate
PublisherPackt
ISBN-139781838648572
Edition2nd Edition
Languages
Right arrow
Author (1)
John Horton
John Horton
author image
John Horton

John Horton is a programming and gaming enthusiast based in the UK. He has a passion for writing apps, games, books, and blog articles. He is the founder of Game Code School.
Read more about John Horton

Right arrow

Saving and loading the high score

File i/o or input/output is a fairly technical subject. Fortunately for us, as it is such a common requirement in programming, there is a library that handles all this complexity for us. Like concatenating strings for our HUD, it is the C++ Standard Library that provides the necessary functionality through fstream.

First, we include fstream in the same way we included sstream:

#include <sstream>
#include <fstream>
#include <SFML/Graphics.hpp>
#include "ZombieArena.h"
#include "Player.h"
#include "TextureHolder.h"
#include "Bullet.h"
#include "Pickup.h"
using namespace sf;

Now, add a new folder in the ZombieArena folder called gamedata. Next, right-click in this folder and create a new file called scores.txt. It is in this file that we will save the player's high score. You can easily open the file and add a score to it. If you do, make sure it is quite a low score so...

lock icon
The rest of the page is locked
Previous PageNext Page
You have been reading a chapter from
Beginning C++ Game Programming. - Second Edition
Published in: Oct 2019Publisher: PacktISBN-13: 9781838648572

Author (1)

author image
John Horton

John Horton is a programming and gaming enthusiast based in the UK. He has a passion for writing apps, games, books, and blog articles. He is the founder of Game Code School.
Read more about John Horton