Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does libstdc++ not implement std::stoi?

Tags:

c++

std

gcc

c++11

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.

like image 576
ManuelSchneid3r Avatar asked Nov 19 '12 12:11

ManuelSchneid3r


People also ask

In which library is stoi function?

std::stoi is a standard library function, not a keyword. A keyword is something like for or new .

Does stoi throw exception?

std::stoi may throw exceptions so it needs to be surrounded by try/catch. In applications where std::stoi may be used frequently, it could be useful to have a wrapper.


1 Answers

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.)

like image 196
Nikos C. Avatar answered Oct 21 '22 19:10

Nikos C.