RoD,
I'm having a problem with getline() in the simple code below, and I was wondering if you could take a look at it. I am trying to read the first 5 char's from each line of an input file that looks like this:
david55555555555
sally66666666666666
but, my output is:
david
I can't figure out what's going on with getline() or the file pointer, so I put a tellg() statement in after the first read of 5 char's, and I get tellg() = -1???
Code:
#include <fstream>
#include <iostream>
#include <string>
using namespace std;
int main()
{
char text[6];
char word[6];
ifstream inFile("C:\\TestData\\input.txt");
inFile.getline(text, 6);
cout<<inFile.tellg()<<endl;
//discard the rest of the char's on the line
inFile.ignore(1000, '\n');
//read the first 5 char's on the next line
inFile.getline(word, 6);
cout<<text<<endl
<<word<<endl;
return 0;
}