title: C++ : Fastest way to read string from stdin
body: <p>We can use getchar_unlocked for fast reading of integers from stdin by manipulating the characters like:</p>
  
  <pre><code>int scan_d()
  {
      int ip = getchar_unlocked(), ret = 0, flag = 1;
  
      for(; ip &lt; '0' || ip &gt; '9'; ip = getchar_unlocked())
      {
          if(ip == '-')
          {
              flag = -1;
              ip = getchar_unlocked();
              break;
          }
      }
  
      for(; ip &gt;= '0'&amp;&amp; ip &lt;= '9'; ip = getchar_unlocked())
          ret = ret * 10 + ip - '0';
      return flag * ret;
  }
  </code></pre>
  
  <p>Is there a way to read strings from stdin in a fast manner using something like above? gets is faster than cin/scanf but at the same time possess critical handling of whitespaces. I thought of modifying the above code for strings but faced problems with whitespaces. Further, it seems reading every character of a string one by one will be slower.</p>
  
  <p>By stdin I mean string is entered by the user (no file handling)</p>