title: How do right read file via stdio? C++
body: <p>I want to read file via stdio for RapidXML. I used following:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;rapidxml.hpp&gt;
  #include &lt;stdio.h&gt;
  #include &lt;Windows.h&gt;
  
  using namespace rapidxml;
  
  int main(int argc, char** argv)
  {
      FILE *pFile;
      pFile = fopen("D:\\ColladaFiles\\sample1.dae", "rb");
      long lSize;
      char *buffer;
      size_t result;
  
      //if error
      if (pFile == NULL) { fputs("File error", stderr); exit(1); }
  
      // obtain file size:
      fseek(pFile, 0, SEEK_END);
      lSize = ftell(pFile);
      rewind(pFile);
  
      // allocate memory to contain the whole file:
      buffer = (char*)malloc(sizeof(char)*lSize);
      if (buffer == NULL) { fputs("Memory error", stderr); exit(2); }
  
      // copy the file into the buffer:
      result = fread(buffer, 1, lSize, pFile);
      if (result != lSize) { fputs("Reading error", stderr); exit(3); }
  
      /* the whole file is now loaded in the memory buffer. */
  
      xml_document&lt;&gt; xdoc;
      xdoc.parse&lt;0&gt;(buffer);
  
      system("pause");
      return 0;
  }
  </code></pre>
  
  <p>RapidXML generated an error. Because If I write buffer following:</p>
  
  <pre><code>std::cout &lt;&lt; buffer &lt;&lt; std::endl;
  </code></pre>
  
  <p>Last line is contains a following:
  <img src="https://i.stack.imgur.com/PrKT4.png" alt="enter image description here">
  How do fast read a file for RapidXML?</p>