Copy data from file.txt to an array

Hello everyone !
I have to make a program where I have to take data from a .txt file and put that information into an INT.array.When I open the file , it looks like this :

125 George
59 Samantha
88 Name
75 Other Name
... ...
Number Name
etc, etc...

So I have to copy only the numbers from the text file and put them into an array. How do I do that ?
Thanks in advance !
1
2
3
4
5
6
7
8
9
10
std::ifstream fin("myfile.txt");
std::string line;
int arr[10], size = 0;

while (fin.good() )
{
  std::getline(fin, line);
  std::stringstream iss(line);
  iss >> arr[size++];
}

Last edited on
Topic archived. No new replies allowed.