int main()
{
int ret(EXIT_SUCCESS);
std::ifstream fp_input("data.txt");
if(fp_input)
{
std::string line;
while(std::getline(fp_input, line))
{
std::istringstream iss(line);
int a(0);
if(iss >> a)
{
std::cout << a << ": ";
int b(0);
while(iss >> b)
std::cout << b << ", ";
if(!iss.eof())
{
std::cerr << "Error reading input\n";
ret = EXIT_FAILURE;
break;
}
std::cout << '\n';
}
else
{
std::cerr << "Error reading input\n";
ret = EXIT_FAILURE;
break;
}
}
}
else
{
std::cerr << "Cannot open input\n";
ret = EXIT_FAILURE;
}
return ret;
}
Note that if the last line of the input file is empty (contains
only a newline character), parsing it will cause an error to
be reported, since your algorithm unconditionally expects an integer
as the first part of a line (the item you read into object 'a').
You'll either need to eliminate this 'requirement', or remove the
blank line.
-Mike