title: Can't get input from user while dealing with strings in file handling
body: <p><strong>I don't know how to deal with that,
  <strong>whenever I run this code, I'm unable to input strings at runtime. The compiler just skips that part.
  Actually, when I remove file handling, the strings work perfectly but when I add File handling then the compiler skips the strings, and when I use <strong>cin.ignore():</strong> , I can enter strings at runtime but the output is all messed up.
  I'm a newbie in programming and I need help.
  Thank you :)</strong></strong>
  help me in</p>
  <blockquote>
  <p>inputting values</p>
  </blockquote>
  <pre><code>    //ofstream to create file.
  //ifstream to read data from file.
  #include &lt;iostream&gt;
  #include &lt;fstream&gt;
  #include &lt;string&gt;
  void write();
  void read();
  using namespace std;
  int main() {
      cout &lt;&lt; &quot;Press 1 to write data into file&quot; &lt;&lt; endl;
      cout &lt;&lt; &quot;Press 2 to read data from file&quot; &lt;&lt; endl;
      int n;
      cin &gt;&gt; n;
      if (n == 1) {
          write();
      }
      else if (n == 2) {
          read();
      }
      else {
          return 0;
      }
      
      system(&quot;pause&quot;);
  }
  void write() {
          string teacher, student;
  cout &lt;&lt; &quot;Enter teacher's name: &quot;;
  getline(cin, teacher);
  cout &lt;&lt; teacher &lt;&lt; endl;
  cin.ignore();
  cout &lt;&lt; &quot;Enter student's name: &quot;;
  getline(cin, student);
  cout &lt;&lt; student &lt;&lt; endl;
  cin.ignore();
  
      ofstream myfile;
      myfile.open(&quot;F://abc.txt&quot;, ios::app);
      myfile &lt;&lt; teacher &lt;&lt; &quot;....&quot; &lt;&lt; student &lt;&lt; endl;
      myfile.close();
  
  }
  
  void read() {
      string teacher, student;
      ifstream myfile;
      myfile.open(&quot;F://abc.txt&quot;);
  
      while (!myfile.eof())
      {
          myfile &gt;&gt; teacher &gt;&gt; student;
  
          cout &lt;&lt; teacher &lt;&lt; &quot; &quot; &lt;&lt; student &lt;&lt; endl;
      }
  
      myfile.close();
  }
  </code></pre>