Use getline()
to read each line into a string, and then construct istringstream
from the string and read numbers from there. Something like this, but with better error checking.
std::ifstream file;
// open file etc.
std::string line;
AdjacencyList al;
while (!file.eof())
{
getline(file, line);
std::istringstream buffer(line);
int num;
buffer >> num;
auto it = al.insert(std::make_pair(num, AdjacencyList::mapped_type()).first;
while (!buffer.eof())
{
buffer >> num;
it->push_back(num);
}
}