• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

Compiling Linux ubuntu compiling error "to_string" is not a member of "std"

Morcega Negra

Banned User
Joined
Aug 4, 2015
Messages
102
Solutions
1
Reaction score
8
fHRVRKQ.jpg


The same source in windows compiles normal, but in linux it gives this problem
 
You need to specify the C++ version, or make your own to_string function using std::stringstream.

C++:
template<typename T>
std::string to_string(const T& n)
{
    std::ostringstream ss;
    ss << n;
    return ss.str();
}

 
You need to specify the C++ version, or make your own to_string function using std::stringstream.

C++:
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_string
 
missing std::to_string means you're missing


C++:
#include <string>

at the top of the file. add that and the compile error should be gone. these errors often occur because compilers often add stuff like <string> when including other stuff. for example in g++ 7.3.0, if you add #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. >.<)

for example, this compiles on g++ BY MISTAKE:


C++:
#include <vector>
// un-comment this to make the code portable: #include <array>
int main(){
    std::array<int,5> arr;
    return 0;
}

and probably does not compile on other compilers like msvc / icc / sun/Borland, where i expect people to get the error "array is not a member of std", for the same reason you're getting to_string is not a member of std here.
 
Last edited:
Back
Top