No Member named stoi in namespace std

半腔热情 提交于 2019-12-01 17:37:48

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.

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>

If you can use stdlib.h, then other way to make it work is to use atoi(const char *)

int myint = atoi(test.c_str());
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!