Intel® C++ Compiler
Community support and assistance for creating C++ code that runs on platforms based on Intel® processors.
7839 Discussions

c++11 : function 'to_string' undefined



I'm playing around with some new features from c++11. One new thing is the 'to_string' method in <string>. I compile with icpc Version Beta with the option '-std=c++11'.


#include <iostream>
#include <string>

int main(void)
    int i = 345;

    std::cout << "The number i = " << std::to_string(i) << std::endl;

    return 0;


However I get back the error at compile time:

main.cpp(9): error: namespace "std" has no member "to_string"
      std::cout << "The number i = " << std::to_string(i) << std::endl;

I'm not very experienced with c++ so I'm probably doing something silly.

0 Kudos
4 Replies
Black Belt

Did you fill out the beta survey, in particular where they ask for priorities on implementation of C++11 features?

Your example works with current Microsoft CL but not with ICL in the same environment.

This seems like a case for a problem report.

On linux, the situation seems more complicated:

I have to omit -std=c++11 to see the error you reported.

If I keep an old enough g++ active (one which doesn't accept -std=c++11) under icpc I get:

jb.cpp(6): error: more than one instance of overloaded function "std::to_string" matches the argument list:
            function "std::to_string(long long)"
            function "std::to_string(unsigned long long)"
            function "std::to_string(long double)"
            argument types are: (int)
          std::cout << "The number i = " << std::to_string(i) << std::endl;

If I change path so as to make a current g++ active, your case runs fine with current released icpc Intel64 as well as on the most recent beta.

I don't expect icpc to fix problems which are caused by using a g++ which isn't recent enough to support your syntax, but you might ask whether icpc should warn you when you ask for -std=c++11 if your g++ is out of date.

0 Kudos

Oh ok. My g++ version is apparently 4.3.4, which I don't think has the new standard.

I'm confused though. Does icpc link against the gcc libraries?

0 Kudos

Yes, icc is using the gcc header files and libraries.


0 Kudos
Valued Contributor II
>>...I'm playing around with some new features from c++11. One new thing is the 'to_string' method in ... I did a quick verification and if string header was implemented before 2010 than it is possible that to_string method was not implemented yet. So, you need to have a set of STL headers ( as a part of GCC installation ) released in 2010 or after. Let me give you a small example related to support of to_string method in Visual Studios: VS 2005 - Not supported VS 2008 - Not supported VS 2010 - Supported VS 2012 - Supported Just open string header file and search for to_string method. If your search is failed try to update a set of STL headers for GCC compiler.
0 Kudos