-5

I have error "Function 'to_string' clould not be resolved" although others C++11 expressions are properly running. I use Eclipse Mars CDT with GCC-C++ 4.9 on Linux Mint.

#include <iostream>
#include <string>

using std::string;

int main()
{
    int a = 123;
    string str = std::to_string(a);
}

Yes, I used -std=c++11, __GXX_EXPERIMANTAL_CXX0X__, and -std=c++0x.

ktoś tam
  • 739
  • 1
  • 6
  • 11
  • 3
    Did you `#include ` and compile with `-std=c++11`? – NathanOliver Oct 20 '15 at 18:37
  • Sorry, I pasted the code wrong. – ktoś tam Oct 20 '15 at 18:57
  • 1
    Welcome to Stack Overflow! what is with the colon after `using std::string`? Please **[edit]** your question with a [mcve] or [SSCCE (Short, Self Contained, Correct Example)](http://sscce.org) – NathanOliver Oct 20 '15 at 19:03
  • @NathanOliver Ok, I corrected this small mistake. – ktoś tam Oct 20 '15 at 19:08
  • `string = std::to_string(a);` will not compile as you do not name a variable – NathanOliver Oct 20 '15 at 19:09
  • @ktośtam You probably meant to write something like: `string str = std::to_string(a);`. – πάντα ῥεῖ Oct 20 '15 at 19:09
  • 1
    `-std=c++11` is good enough - do not apply ` __ GXX_EXPERIMANTAL_CXX0X __, and -std=c++0x.` –  Oct 20 '15 at 19:10
  • @πάνταῥεῖ Ok, it's now correct. – ktoś tam Oct 20 '15 at 19:13
  • @ktośtam Don't edit your question to be a moving target! That's not helpful or constructive. I don't believe anymore that's your _real_ code now. Provide a [MCVE] that reproduces your error, period. – πάντα ῥεῖ Oct 20 '15 at 19:13
  • @DieterLücking Not in Eclipse. [\__GXX_EXPERIMENTAL_CXX0X__](http://stackoverflow.com/questions/17131744/eclipse-cdt-indexer-does-not-know-c11-containers) [-std=c++0x](http://wiki.eclipse.org/index.php/CDT/User/FAQ) – ktoś tam Oct 20 '15 at 19:15
  • @ktośtam Nothing to do with eclipse. The toolchain version used might be relevant. – πάντα ῥεῖ Oct 20 '15 at 19:19
  • @πάνταῥεῖ I edited, because I was pasting the code wrong and finaly there wero no code. Next I add "Yes, I used -std=c++11, __GXX_EXPERIMANTAL_CXX0X__, and -std=c++0x.", because I thought it is'n necessary, when there is "others C++11 expressions are properly running". My code is too long and I added that simple example, because it's everything, what make the problem. – ktoś tam Oct 20 '15 at 19:27
  • @πάνταῥεῖ It isn't working good without it. I followed instructions in Eclipse site and in others questions. – ktoś tam Oct 20 '15 at 19:31

1 Answers1

1

It is highly likely that you forgot #include <string> or you forgot to specify the namespace std::

dev_dev
  • 27
  • 1