Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

No Member named stoi in namespace std

I am testing out std::stoi function found in the link below: http://en.cppreference.com/w/cpp/string/basic_string/stol
but I got the error:

No Member named stoi in namespace std.

What should I do? Please advise thanks.

P.S: I am using Xcode Ide to do my c++.

#include <iostream>
#include <string>

int main()  {
   std::string test = "45";
   int myint = std::stoi(test);
   std::cout << myint << '\n';
}

Image

no member named stoi in namespace 'std'

error

like image 542
user2211678 Avatar asked Oct 20 '13 14:10

user2211678


2 Answers

std::stoi is available only since C++11. In case you don't have C++11 support, here's the C++03 solution based on std::istringstream:

std::string test = "45";
std::istringstream is(test);
int myInt;
if (is >> myInt)
    std::cout << myint << std::endl;

you just need to #include <sstream>

like image 60
LihO Avatar answered Sep 28 '22 15:09

LihO


First of all, you need a compiler that supports C++11 and you need to compile in "C++11 mode" (in some cases).

Secondly, if this is in fact an intellisense issue (and it looks like it may be), then it could simply be that your IDE doesn't support C++11 yet.

like image 30
Lightness Races in Orbit Avatar answered Sep 28 '22 13:09

Lightness Races in Orbit