std::stringstream object unrecognized in std::to_string replacement function : <p>Since std::to_string doesn't work for me, and since I'm working on a very difficult environment at the moment (I'm working on Android using a Linux terminal emulator), I've decided to leave it broken and use a user-made function instead to replace it (I've found it online).</p>

<p>Here's the exact code I'm using:</p>

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

namespace patch {
    template &lt;typename T&gt;
    std::string to_string(const T &amp;n);
        std::stringstream stm;
        stm &lt;&lt; n;
        return stm.str();
    }
}
</code></pre>

<p>I'm compiling it using these tags:</p>

<pre><code>g++ -std=c++11 -g -Wall -Wextra -pedantic
</code></pre>

<p>And I'm getting these errors:</p>

<pre><code>unknown type name 'stm'; did you mean 'tm'?
                stm &lt;&lt; n;
                ^~~
</code></pre>

<p>(then a note on <code>tm</code> being declared somewhere in <code>include/time.h</code>)</p>

<pre><code>expected unqualified-id
                return stm.str();
                ^
</code></pre>

<p>And then also an "extraneous closing brace" error for the last brace which closes the namespace brace.</p>

<p>As I understand it, it doesn't recognize the line <code>stm &lt;&lt; n;</code> as the method <code>operator &lt;&lt;</code> used on a <code>std::stringstream</code> object, but instead  as some variable declariation for some reason.</p>

<p>Why exactly am I getting those errors? Is there a way to fix them? If not, what can I use to replace even this solution?</p>
