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).
Here's the exact code I'm using:
#include <sstream>
namespace patch {
template <typename T>
std::string to_string(const T &n);
std::stringstream stm;
stm << n;
return stm.str();
}
}
I'm compiling it using these tags:
g++ -std=c++11 -g -Wall -Wextra -pedantic
And I'm getting these errors:
unknown type name 'stm'; did you mean 'tm'?
stm << n;
^~~
(then a note on tm
being declared somewhere in include/time.h
)
expected unqualified-id
return stm.str();
^
And then also an "extraneous closing brace" error for the last brace which closes the namespace brace.
As I understand it, it doesn't recognize the line stm << n;
as the method operator <<
used on a std::stringstream
object, but instead as some variable declariation for some reason.
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?