0

I'm getting some junk value instead of first character. I think i have gone wrong in reading the stream position

string line;
int count=0;
streampos a[10];
fstream question("filename.txt");
while(!question.eof())
{
     a[count]=question.tellg();
     getline(question,line);
     count++;
 }
  //   cout<<count;
 int temp=0;char ch;
 while(temp<count)
 {
      question.seekg(a[temp++],ios::beg);
      question>>ch;
      cout<<ch<<endl;
 }
Pavan C
  • 1
  • 2
  • http://stackoverflow.com/a/5605159/1171191 - try `while(std::getline(question, line)) ...` and see where you go from there. – BoBTFish Mar 29 '15 at 17:58
  • That's *a* problem, but are you sure it solves everything here? – BoBTFish Mar 29 '15 at 18:03
  • u mean replace getline(question,line) with std::getline(question,line)? didn't work though. – Pavan C Apr 02 '15 at 16:21
  • I'm not getting first position(character) of a line but some other character instead – Pavan C Apr 02 '15 at 16:26
  • No, I mean put the read into the `while` condition. Checking `eof` in a `while` is almost always wrong, as the duplicate explains. – BoBTFish Apr 03 '15 at 07:15
  • tried that but i don't get first position(character). I still get the same output(character) as earlier. – Pavan C Apr 04 '15 at 13:03

0 Answers0