title: my code runs fine on VS 2017 but have undesired output with the writeFile() . It keeps taking input after the delim character. can anyone help me?
body: <pre><code>#include &lt;iostream&gt;
  #include &lt;fstream&gt;
  #include &lt;string&gt;
  
  using namespace std;
  
  void writeFile(fstream&amp; file)
  {
      file.open(&quot;writing.txt&quot;, ios::out);
      if (file.is_open())
      {
          string holdLine;
          cout &lt;&lt; &quot;Please write to the file from console!!!&quot; &lt;&lt; endl;
          while (getline(cin, holdLine, '-'))
              file &lt;&lt; holdLine&lt;&lt; endl;
      }
      file.close();
  }
  
  void readFile(fstream&amp; file)
  {
      file.open(&quot;writing.txt&quot;, ios::in);
      if (file.is_open())
      {
          string holdLine;
          while (getline(file, holdLine))
          {
              cout &lt;&lt; holdLine &lt;&lt; endl;
          }
      }
      file.close();
  }
  
  
  int main()
  {
      fstream sampleFile;
      writeFile(sampleFile);
      readFile(sampleFile);
  
  }
  </code></pre>
  <p>// I am guessing this while (getline(cin, holdLine, '-')) loop is the one causing problem
  // I test readFile() and it works fine but whenever writeFile() runs it goes on infinite loop</p>