cout and String concatenation
<p>I was just reviewing my C++. I tried to do this:</p>

<pre><code>#include &lt;iostream&gt;

using std::cout;
using std::endl;

void printStuff(int x);

int main() {
    printStuff(10);
    return 0;
}

void printStuff(int x) {
    cout &lt;&lt; "My favorite number is " + x &lt;&lt; endl;
}
</code></pre>

<p>The problem happens in the <code>printStuff</code> function. When I run it, the first 10 characters from "My favorite number is ", is omitted from the output. The output is "e number is ". The number does not even show up.</p>

<p>The way to fix this is to do  </p>

<pre><code>void printStuff(int x) {
    cout &lt;&lt; "My favorite number is " &lt;&lt; x &lt;&lt; endl;
}
</code></pre>

<p>I am wondering what the computer/compiler is doing behind the scenes.</p>