15

I want to use std::stoi. Although I could use ::atoi(str.c_str()) it would make the code cleaner if this would work. But Eclipse tells me:

Function 'stoi' could not be resolved

I checked that

  • the header <string> is included,
  • include paths are set correctly, as I can use std::string,
  • the compiler flag -std=c++0x -std=c++11 is set too.

Is stoi() missing in gcc, or is it somehow my fault?

I am using gcc (Debian 4.7.2-4) 4.7.2.

6
  • 1
    If anything, it would be missing from libstdc++, not GCC... Commented Nov 19, 2012 at 12:25
  • Is the compiler flag not -std=c++0x ? Commented Nov 19, 2012 at 12:25
  • Yes, just checked it. Both are set. Commented Nov 19, 2012 at 12:27
  • You should probably have only -std=c++11. Can't imagine that would cause this bug though. (Also, just to confirm, you are either using std::stoi or pulling in the std namespace?) Wait.... Will it compile? Like Nikos C. said below, it might just be Eclipse complaining. Commented Nov 19, 2012 at 12:27
  • @DevNoob: it is not about gcc. Please, rename the question. Commented Nov 19, 2012 at 12:35

2 Answers 2

17

You're using GCC 4.7.2, so std::stoi is supported. You can ignore the Eclipse warning. It should compile and run fine. The problem is with the Eclipse editor, not with GCC.

(You only need the -std=c++11 or -std=gnu++11 [to also get the GCC extensions] flag, btw. -std=c++0x is just a deprecated synonym.)

Sign up to request clarification or add additional context in comments.

5 Comments

c++11 and gnu++11 are different.
@SergeyK. I know. But both enable C++-11 support.
Okay, yes your right. It compiles. Can I somehow do something aganist these Eclipse errors?
+1 Hah, nice one. Try to compile it before taking Eclipse's stupid complaints too serious.
5

You can get rid of the red squiggles in eclipse, (from here):

Project Properties->C/C++ General->Preprocessor Include Paths, Macros->[Providers] tab->your Built-in Compiler Settings provider (toolchain dependent). Click on "Workspace Settings" link which gets you to "Settings" property page, select [Discovery] tab and your provider again. There is "Command to get compiler specs", add "-std=c++11" in there.

hit apply and close everything, then index->rebuild and you should be all set.

Or, if your version of eclipse is older, you might just have to do this:

Project->Properties->C/C++ Build->Discovery Options->GCC C++ Compiler

and add the "-std=c++11" flag to the invocation arguments there. This is "deprecated" though, so you may want to consider updating Eclipse since you're updating your compiler too.

3 Comments

I read this in the eclipse FAQ, but the problem was, that it was not set permanent. It chnaged nothing and after reopening project settings the flag has dissapeared.
It fixed it permanently for me. You might have to close eclipse and re-open?
Goddamn. okay its permanent. But __GXX_EXPERIMENTAL_CXX0X__ solves the stoi problem. But raises a vector.insert problem. but your way does not solve stoi problem. Its horrible.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.