C++ overloaded << operator does not correctly output unless I include an endl
<p>pretty interesting issue I'm having. </p>

<p>Basically I'm overloading the insertion operator to return a string representation of my class. However, the program just terminates unless I include a std::endl.</p>

<pre><code>template&lt;class T&gt;
std::ostream&amp; operator &lt;&lt; (std::ostream&amp; outs, const LinkedQueue&lt;T&gt;&amp; q) {

    outs &lt;&lt; "queue[";

    if (!q.empty()) {
        outs &lt;&lt; q.front-&gt;value;

        for (auto i = ++q.begin(); i != q.end(); ++i)
            outs &lt;&lt; ',' &lt;&lt; *i;
    }
    outs &lt;&lt; "]:rear";

    return outs;
}

int main() {
    QueueType queueType1;
    queueType1.enqueue("L");
    std::cout &lt;&lt; queueType1 &lt;&lt; std::endl;
   return 0;
}
</code></pre>

<p>The above main produces the correct output of: queue[L]:rear</p>

<p>But, if I remove the <code>std::endl</code> from main, the program breaks and produces nothing. </p>

<p>I cannot include an <code>endl</code> in the overloaded method because it adds an extra character to my string that I do not what. Any suggestions? </p>