Morcega Negra
Banned User
- Joined
- Aug 4, 2015
- Messages
- 102
- Solutions
- 1
- Reaction score
- 8
The same source in windows compiles normal, but in linux it gives this problem
to_string function using std::stringstream.template<typename T>
std::string to_string(const T& n)
{
std::ostringstream ss;
ss << n;
return ss.str();
}
Should wrap that to_string fix inside std namespace to avoid manually changing each instance of std::to_string to to_stringYou need to specify the C++ version, or make your ownto_stringfunction usingstd::stringstream.
C++:template<typename T> std::string to_string(const T& n) { std::ostringstream ss; ss << n; return ss.str(); }
![]()
"to_string" isn't a member of "std"?
Okay, so I have tmp.cpp: #include <string> int main() { std::to_string(0); return 0; } But when I try to compile I get: $ g++ tmp.cpp -o tmp tmp.cpp: In function ‘int main()’: tmp...stackoverflow.com
![]()
to_string is not a member of std, says g++ (mingw)
I am making a small vocabulary remembering program where words would would be flashed at me randomly for meanings. I want to use standard C++ library as Bjarne Stroustroup tells us, but I havestackoverflow.com
Thanks for the tips, but you do not even know where to start.Should wrap that to_string fix inside std namespace to avoid manually changing each instance of std::to_string to to_string
#include <string>
#include <vector> then you can also use std::array without including <array>, but code that only includes <vector> to use std::array is non-portable, and the code may not compile on another compiler (like MSVC, for instance)... and i consider this behavior in g++ A BUG. (but the gcc devs does not, as the c++ specs technically does not forbid it. >.<)#include <vector>
// un-comment this to make the code portable: #include <array>
int main(){
std::array<int,5> arr;
return 0;
}
to_string is not a member of std here.