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 the complexity for us. As with concatenating strings for our HUD, it is the Standard Library that provides the necessary functionality through fstream
.
First, we include fstream
in the same way we included sstream
:
#include "stdafx.h"
#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/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 could open the file and add a score to it. If you do, make sure it is...