file input seekg() behaving oddly

I'm trying to figure out how to get numbers from files, and while I can read the numbers and convert them to integers, I run into issues when trying to read multiple integers separated by spaces. Here is the code.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <iostream>
#include <fstream>
#include <string>


int main()
{
	std::fstream things("/home/canaan/Desktop/storeUnit.txt");
	std::string data;
	int trueData;
	int x(0);
	do{
	getline(things, data, ' ');
	trueData = std::stoi(data, nullptr, 10);
	std::cout << trueData << std::endl;
	things.seekg(3, std::ios::cur);
	} while(x<10);
	return 0;
}

I'm wanting it to print the contents of the file ("10 20 30 40 50 60 70 80 90", without quotes) each separated with a newline, but it instead prints every other number and terminates in an error when it attempts to read beyond the end of the file. I think this has something to do with seekg(). If I put an extra three spaces between each number it prints fine, but I don't know why.
An easy way to do it:
1
2
3
4
5
std::fstream things("/home/canaan/Desktop/storeUnit.txt");
// check if things opened correctly
int num;
while(things >> num)
  cout << num << "\n";
Topic archived. No new replies allowed.