What I want to do is read lines from a text file that contain two integers and remaining are strings on each line. For example, it may look something like this:
1 2 abc def pq
1 3 abc def
10 12 abc pq rt
I have till now found out how to read 2 integers and 1 string on each line but I'm really having trouble reading the whole input file as given above. Following is the code that I have tried:
#include <iostream>
#include<string>
#include<fstream>
using namespace std;
int main() {
ifstream file( "Foodtest.txt", ios::in );
string part1;
int num1, num2;
if( !file )
cerr << "Cant open " << endl;
while( file >> num1 >> num2 >> part1 )
{
cout << num1 << " " << num2
<< " " << part1 << endl;
}
file.close();
return 0;
}