title: Demonstration of noskipws in C++
body: <p>I was trying out the noskipws manipulator in C++ and I wrote following code. </p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;sstream&gt;
  #include &lt;string&gt;
  using namespace std;
  
  int main()
  {
      string first, middle, last;
  
      istringstream("G B Shaw") &gt;&gt; first &gt;&gt; middle &gt;&gt; last;
      cout &lt;&lt; "Default behavior: First Name = " &lt;&lt; first &lt;&lt; ", Middle Name = " &lt;&lt; middle &lt;&lt; ", Last Name = " &lt;&lt; last &lt;&lt; '\n';
      istringstream("G B Shaw") &gt;&gt; noskipws &gt;&gt; first &gt;&gt; middle &gt;&gt; last;
      cout &lt;&lt; "noskipws behavior: First Name = " &lt;&lt; first &lt;&lt; ", Middle Name = " &lt;&lt; middle &lt;&lt; ", Last Name = " &lt;&lt; last &lt;&lt; '\n';
  }
  </code></pre>
  
  <p>I expect the following output:</p>
  
  <p><strong>Expected Output</strong></p>
  
  <pre><code>Default behavior: First Name = G, Middle Name = B, Last Name = Shaw
  noskipws behavior: First Name = G, Middle Name = , Last Name = B
  </code></pre>
  
  <p><strong>Output</strong></p>
  
  <pre><code>Default behavior: First Name = G, Middle Name = B, Last Name = Shaw
  noskipws behavior: First Name = G, Middle Name = , Last Name = Shaw
  </code></pre>
  
  <p>I modified this code to make it work for chars like this and it works perfectly fine.</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;sstream&gt;
  #include &lt;string&gt;
  using namespace std;
  
  int main()
  {
      char first, middle, last;
  
      istringstream("G B S") &gt;&gt; first &gt;&gt; middle &gt;&gt; last;
      cout &lt;&lt; "Default behavior: First Name = " &lt;&lt; first &lt;&lt; ", Middle Name = " &lt;&lt; middle &lt;&lt; ", Last Name = " &lt;&lt; last &lt;&lt; '\n';
      istringstream("G B S") &gt;&gt; noskipws &gt;&gt; first &gt;&gt; middle &gt;&gt; last;
      cout &lt;&lt; "noskipws behavior: First Name = " &lt;&lt; first &lt;&lt; ", Middle Name = " &lt;&lt; middle &lt;&lt; ", Last Name = " &lt;&lt; last &lt;&lt; '\n';
  }
  </code></pre>
  
  <p>I know how cin works and I wasn't able to figure out why it works this way in case of <code>string</code>.</p>