Weird behaviour when assigning a char to a int variable
<p>Given this code:</p>

<pre><code>#include &lt;cstdio&gt;
#include &lt;iostream&gt;
#include &lt;string&gt;
using std::cin;
using std::cout;
using std::string;

int main() {
        int a;
        string b;

        cin &gt;&gt; a;
        cin &gt;&gt; b;

        return 0;
}
</code></pre>

<p>I tried compiling it with g++ and running it.
When assigning a char to <code>a</code>, at the first <code>cin</code>, the following instruction seems to be skipped.</p>

<p>Even if add two <code>getchar()</code> instructions between the last two lines, only the second <code>getchar()</code> seems to be executed.
Can somebody accurately explain what's happening at low level, which seemingly results in an apparent non execution of those lines?</p>

<p><strong>EDIT:</strong></p>

<p>Using this debug code:</p>

<pre><code>#include &lt;cstdio&gt;
#include &lt;iostream&gt;
#include &lt;string&gt;
using std::cin;
using std::cout;
using std::endl;
using std::string;

int main() {
        int a;
        string b;

        cin &gt;&gt; a;
        cin &gt;&gt; b;
        cout &lt;&lt; "a is "&lt;&lt; a &lt;&lt; endl;
        cout &lt;&lt; "b is "&lt;&lt; b &lt;&lt; endl;
        getchar();

        return 0;
}
</code></pre>

<p><strong>INPUT</strong> 
1test</p>

<p><strong>OUTPUT</strong>
a is 1
b is test
* No getchar executed *</p>

<p><strong>INPUT</strong>
1
test</p>

<p><strong>OUTPUT</strong>
a is 1
b is test</p>

<p><strong>INPUT</strong>
ttest</p>

<p><strong>OUTPUT</strong>
a is 0
b is </p>

<p><strong>INPUT</strong>
t</p>

<p>// Skips the second <code>cin</code></p>

<p><strong>OUTPUT</strong>
a is 0
b is</p>

<p>NOTE:
<code>getchar()</code> was not executed even once.</p>
