Typically, programs like yours are for reading many records that are arranged identically, so you just pick out the information at the same location for every record.
One thing to think about is: getline() is for strings, but if you don't have to do any numerical calculations with the numbers, you can just read them as strings and display them.
Here is an example:
Code:
#include<iostream>
#include <fstream>
using namespace std;
int main()
{
ifstream inFile("C:\\TestData\\input.txt");
char junk[100];
int start, number;
double end;
inFile.getline(junk, 100);
inFile.getline(junk, 100);
inFile>>start;
inFile.ignore();//To remove the '\n' at the end of the line
//left by the >> operator in the previous line
inFile.getline(junk, 100);
inFile>>end;
inFile.ignore();
inFile.getline(junk, 100);
inFile>>number;
cout<<start<<endl;
cout<<end<<endl;
cout<<number<<endl;
return 0;
}
The cin.ignore() line is necessary or the subsequent getline() attempt will get messed up. getline() stops reading when it encounters a '\n', and the >> operator leaves the '\n' in the input stream. So, after this line is executed:
inFile>>start;
there will still be a '\n' sitting in the input stream as the next character to be read, so getline() will only read that character and then end, but you need it to read in the whole next line. The solution is to use cin.ignore(), which skips one character.
If the numbers could be on any line in the file, then you have to read in each line as a string, test for an alpha numeric character at the first position, if there isn't one--discard the string, if there is one and you need to use it in a numerical calculation, you need to convert it to a number using a function like atoi() (-->alpha to int).