'C++ read only integers in an fstream

How do I read in a file and ignore nonintegers? I have the part down where I remove the ',' from the file, but also need to remove the first word as well.

#include <iostream>
#include <fstream>
#include <sstream>
using namespace std;

above is all the STL I am using.

string line, data;

int num;

bool IN = false;

ifstream file;

file.open(filename);
if (!file)
{
    cout << "File is not loading" << endl;
    return;
}
while (getline(file, line))
{
    stringstream ss(line);
    while (getline(ss, data, ','))
    {
        if (!stoi(data))
        {
            break;
        }
        else
        {
            num = stoi(data);
            if (IN == false)
            {
                //h(num);
                //IN = true;
            }
        }
    }
}

The file I am trying to read from is

3
Andrew A,0,1
Jason B,2,1
Joseph C,3,0

Basically, I am able to just completely ignore the names. I just need the numbers



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source