Well, its up to to you. For example you could make sure the data is always in a specific sequence, so that line 1 contains the level, line 2 contains the weapon and so on.
A more flexible arrangement is to use a keyword followed by its value
For example the file might look like this:
level 1
weapon peashooter
Or use a particular delimiter, such as an equal sign:
level=2
weapon=rifle
As you can see, there are many choices of how to store the data. Depending on that decision, the means of retrieving the value would vary.
There are two problems here. The first is identifying what type of information is on a particular line. The second is that some data could be either a string or a number (I assume - but you haven't actually said so).
In simple terms, read the first value on the line as a string. Depending on its contents, decide what to do next.
1 2 3 4 5 6 7 8 9
|
string keyword;
int level = 0; // default value
string weapon = "feather"; // default value
infile >> keyword;
if (keyword == "level")
infile >> level;
else if (keyword == "weapon")
infile >> weapon;
|