title: Ctrl+Z behaviour in terminal
body: <pre><code>string s;
  while(getline(cin,s)){
      cout &lt;&lt; "---" &lt;&lt; endl
      for(auto c: s) cout &lt;&lt; int(c) &lt;&lt; endl;   
  }
  cout &lt;&lt; "Exiting";
  </code></pre>
  
  <p>If my input is <kbd>Ctrl</kbd>+<kbd>Z</kbd>, then I press enter once, and my program exits immediately.</p>
  
  <pre><code>^Z
  Exiting
  </code></pre>
  
  <p>If I enter a character before pressing <kbd>Ctrl</kbd>+<kbd>Z</kbd>, then I have to press enter twice, and my program does not exit.</p>
  
  <pre><code>s^Z
  
  ---
  115
  26
  </code></pre>
  
  <p>I had always interpreted <kbd>Ctrl</kbd>+<kbd>Z</kbd> as the EOF character. <code>getline</code> would continue until it reaches this character, at which point <code>getline</code> tests false and my program would exit. I'm curious why my program interprets <kbd>Ctrl</kbd>+<kbd>Z</kbd> as the <a href="https://en.wikipedia.org/wiki/Substitute_character" rel="nofollow noreferrer">substitute character</a> 26, depending on whether there is a preceding character or not, and why it was necessary for me to press Enter twice in the second example?</p>