title: Convert any type to string c++
body: <p>How could I convert any type to a string in C++?</p>
  
  <pre><code>std::string val;
  
  template&lt;typename T&gt; std::string AnyToString(T val) {
       return (std::string)val;
  }
  
  template&lt;typename T&gt; void SetVal(T val) {
      this-&gt;val = AnyToString(val);
  }
  
  int main() {
      SetVal(10);
      return 0;
  }
  </code></pre>
  
  <p>Above code gives me an error, cannot convert int to string.
  reinterpret_cast&lt;>, static_cast&lt;>, etc. don't work either.</p>