Reading Integers From *.Txt Files

I am trying to create a simple text-based game with highscores, and I am having trouble reading integers from a text files.

I use fstream score("highscore.txt") to open the file.
Then I do score >> x, score >> y, and score >> z.

My goal was to read a single number into all three variables, but it is instead reading several numbers into each one.
Highscore.txt is 28 numbers with no whitespace.

How would I either limit the numbers read to one, or limit the numbers int x, y, and z store to one? Any help is appreciated!

I am using Visual C++ compiler, by the way.
Last edited on
can you post your file here and tell what output you want in x,y,z.
you could try saving the "highscore" in highscore.txt this way
 
1300 6000 3000


where 1300 is the first high score, 6000 is the 2nd, and 3000 is the 3rd

1
2
3
4
int score1, score2, score3;
fstream score("highscore.txt")
score>>x>>y>>z;
score1=x, score2=y, score3=z;


i have tried saving numbers in text with spaces between it. i suppose the program only reads files that are separated in spaces.
i am having trouble though in saving files in *.bin.

hope this could help.^_^

[correct me if i am wrong/misspelled something]
Topic archived. No new replies allowed.