title: Loop getting cin input
body: <p>Is it possible to create a while loop like:</p>
  
  <pre><code>bool stop_input = false;
  
  while (!stop_input) {
      // Keep getting inputed string
      // Maybe like std::getline(std::cin, str_input);
  }
  </code></pre>
  
  <p>Where this would keep looping and getting what the user inputted into console without stopping (freezing) like when doing<code>std::cin</code> or <code>std::getline()</code>.</p>
  
  <p>I am interested in this to have a seperate thread which would do other stuff while waiting for user to input something and press enter then <code>stop_input</code> would go true and the user input would get disabled.</p>
  
  <p>Is this possible? How?</p>
  
  <p>EDIT:</p>
  
  <p>For example If I did:</p>
  
  <pre><code>void test()
  {
      std::string str;
      while (!stop_input) {
          std::getline(std::cin, str);
      }
  }
  </code></pre>
  
  <p>If I created a function like above, compiled it and started a debugger, the debugger (program) would stop when std::getline() would get called the second time. I dont want this to happen, I want this loop to run continiously untill stopped by setting <code>stop_input = true;</code></p>
  
  <p>EDIT2:</p>
  
  <p>Main thread:</p>
  
  <pre><code>void someFunction()
  {
      string read_input;
      thread get_input = thread(readInput, &amp;read_input);
  
      while(1) {
          if (buttonPressed(ENTER) {
              stop_input = true;
              get_input.join();
  
              // Do something with 'read_input' string.
          } else if (buttonPressed(ESC) {
             stop_input = true;
             get_input.join()
  
             // Discard 'read_input' string and return from this function.
             break;
          }
      }
  }
  </code></pre>
  
  <p>Reading thread:</p>
  
  <pre><code>void readInput(string* input)
  {
      while (!stop_input) {
          //Get input
      }
  }
  </code></pre>
  
  <p>P.S. Ofcourse main thread would be doing some work behind also, not related to input reading.</p>