title: Reading multiple string lines, c++ to multiple variables;
body: <p>I am trying to read such input data in c++;</p>
  
  <p>Input:</p>
  
  <p>Hi, I am John. How are you?</p>
  
  <p>I am</p>
  
  <p>How are you</p>
  
  <p>I want to store the first string line to s, second line string to subs1, third string line to subs2.</p>
  
  <p>I tried using getline for each line, it would not work.</p>
  
  <pre><code>#include &lt;iostream&gt;
  //#include &lt;cmath&gt;
  //#include &lt;climits&gt;
  #include &lt;string&gt;
  
  using namespace std;
  int main() {
      freopen("input.txt", "r", stdin);
      freopen("output.txt", "w", stdout);
  
      string s, sub1, sub2;
      getline(cin, s);
      getline(cin, sub1);
      getline(cin, sub2);
  </code></pre>
  
  <p>How can I achieve that?</p>
  
  <p>Also, what is the difference between:</p>
  
  <pre><code>#include &lt;iostream&gt;
  //#include &lt;cmath&gt;
  //#include &lt;climits&gt;
  #include &lt;string&gt;
  
  using namespace std;
  int main() {
      freopen("input.txt", "r", stdin);
      freopen("output.txt", "w", stdout);
      int n;
      cin &gt;&gt; n;
      string s = "", s1;
      for (int i = 0; i &lt; n; i++) {
          getline(cin, s1);
          s += s1;
      }
      cout &lt;&lt; s;
      return 0;
  }
  </code></pre>
  
  <p>and :</p>
  
  <pre><code>#include &lt;iostream&gt;
  //#include &lt;cmath&gt;
  //#include &lt;climits&gt;
  #include &lt;string&gt;
  
  using namespace std;
  int main() {
      freopen("input.txt", "r", stdin);
      freopen("output.txt", "w", stdout);
      int n;
      cin &gt;&gt; n;
      string s = "", s1;
      while (getline(cin, s1)) {
          s += s1; 
      }
      cout &lt;&lt; s;
      return 0;
  }
  </code></pre>