Reading Files

Hi Everybody.........
I am facing a problem with file handling...
I have created a text document manually and given some name to that. i have placed this document in the c++ project folder and then i have tried read the file using the code snippet as
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include <fstream>
#include <iostream>
using namespace std;

int main () 
{
  char buffer[256];
  ifstream myfile ("ex.xml");

  while (! myfile.eof() )
  {
    myfile.getline (buffer,100);
    cout << buffer << endl;
  }
  return 0;
}


The output console window continuously scrollingdown without printing any data.
I have saved the document as .xml file.the dat in the file is
<?xml version="1.0"?>
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
Try

1
2
3
4
  while (myfile.getline (buffer,100))
  {
    cout << buffer << endl;
  }

Topic archived. No new replies allowed.