1

I want to use C++ to read an XML file, but when I type the following:

char infile[] = "util_sip.xml";
ifstream in(infile);
char buffer[256];
assert(in.si_open());

while(!in.eof()){
    in.getline(buffer, 256);
    cout<<buffer<endl;
}

It doesn't work and it prints nothing on my screen and causes an infinite loop. However, if I type:

while(in.getline(buffer,strsize)){
    cout<<buffer<<endl;
}

It works again. I don't know why it doesn't work when I run the first example.

Willem van Ketwich
  • 5,666
  • 7
  • 49
  • 57
Aaron Hao
  • 59
  • 8
  • 3
    I don't know if it is the cause of your particular problem, but the `!in.eof()` loop is wrong: https://stackoverflow.com/questions/5605125/why-is-iostreameof-inside-a-loop-condition-considered-wrong – Thomas Padron-McCarthy Oct 31 '17 at 06:56

0 Answers0