title: getline has a strange behaviour in reading a text file
body: <p>I have a strange behaviour with a piece of code I have wrote. There is the code :</p>
  <pre><code>#include &quot;pugixml.hpp&quot;
  
  #include &lt;cassert&gt;
  #include &lt;string&gt;
  #include &lt;iostream&gt;
  #include &lt;fstream&gt;
  #include &lt;optional&gt;
  
  namespace xml = pugi;
  
  void read_ascii_file(const std::string&amp; filename)
  {
    std::ifstream file(filename, std::ios::in);
  
    if(!file) {
      std::cerr &lt;&lt; &quot;[ERREUR - read_ascii_file] Impossible d'ouvrir le fichier &quot; &lt;&lt; filename &lt;&lt; &quot;! Vérifier son existence.&quot; &lt;&lt; std::endl;
      abort();
    }
  
    std::string tmp;
    while(std::getline(file, tmp))
      {
        //Do nothing here
      }
    file.close();
  }
  
  class Foo{
  
  public:
    Foo(const xml::xml_document&amp; doc)
    {
      _base_node = doc.child(&quot;test&quot;);
  
      std::string id = _base_node.child(&quot;data1&quot;).child_value(&quot;id&quot;);
      std::cout &lt;&lt; &quot;id from constructor &quot; &lt;&lt; id &lt;&lt;std::endl;
    }
  
    void bar()
    {
      std::string id = _base_node.child(&quot;data2&quot;).child_value(&quot;id&quot;);
      std::cout &lt;&lt; &quot;id from bar &quot; &lt;&lt; id &lt;&lt;std::endl;
    }
  
  private:
    xml::xml_node _base_node;
  
  };
  
  std::optional&lt;Foo&gt; make(const std::string&amp; filename)
  {
    xml::xml_document doc;
    xml::xml_parse_result result = doc.load_file(filename.c_str());
  
    if(result.status != xml::xml_parse_status::status_ok)
      return {};
    else
      return Foo(doc);
  }
  
  int main()
  {
    std::string filename = &quot;xml_test.dat&quot;;
    std::optional&lt;Foo&gt; f = make(filename);
  
    if(!f)
      std::abort();
    else
      {
        std::string filename = &quot;lbl-maj_for_test.dat&quot;;
        //read_ascii_file(filename);
        f-&gt;bar();
      }
  
    return 0;
  }
  </code></pre>
  <p>The file xml_test.dat is :</p>
  <pre><code>&lt;test&gt;
    &lt;data1&gt;
      &lt;id&gt;1&lt;/id&gt;
    &lt;/data1&gt;
    &lt;data2&gt;
      &lt;id&gt;2&lt;/id&gt;
    &lt;/data2&gt;
  &lt;/test&gt;
  </code></pre>
  <p>This code giving an output :</p>
  <blockquote>
  <p>id from constructor 1</p>
  <p>id from bar 2</p>
  </blockquote>
  <p>But when I uncomment the line <code>//read_ascii_file(filename);</code>, the output become :</p>
  <blockquote>
  <p>id from constructor 1</p>
  <p>Erreur de segmentation</p>
  </blockquote>
  <p>gdb give me the error :</p>
  <pre><code>#0  0x00007ffff7f84b20 in pugi::xml_node::child(char const*) const () from /lib/x86_64-linux-gnu/libpugixml.so.1
  #1  0x00005555555578ba in Foo::bar (this=0x7fffffffdf40) at /home/guillaume/dev/C++/projects/moteur_de_calcul/test/test_xml_node.cpp:42
  #2  0x00005555555575ec in main () at /home/guillaume/dev/C++/projects/moteur_de_calcul/test/test_xml_node.cpp:73
  </code></pre>
  <p>The file lbl-maj_for_test.dat is a txt file of 132 lines and none seems to have a length more than 50 characters. I think to a an encoding problem, but I have no clue how I can resolve this problem ...</p>