Constructing a temp object and calling a method that returns a pointer - is it safe?
<p>My intution says it isn't, but the fact that everything is going on in the same line is a bit confusing. I wonder if the pointer is still valid when <code>cout</code> uses it.</p>

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

struct A {
    A() : m_s("test"){ }
    const char* c_str() { return m_s.c_str(); }
    std::string m_s;
};

int main() {
    std::cout &lt;&lt; "abc " &lt;&lt; A().c_str() &lt;&lt; " def" &lt;&lt; std::endl;
}
</code></pre>
