C++ 命名空间std中没有名为stoi的成员

C++ 命名空间std中没有名为stoi的成员,c++,string,parsing,compiler-errors,string-parsing,C++,String,Parsing,Compiler Errors,String Parsing,我正在测试以下链接中的std::stoi函数: 但我得到了一个错误: 命名空间std中没有名为stoi的成员 我该怎么办? 请告知,谢谢 S:我使用XCIDE IDE来做我的C++。 #include <iostream> #include <string> int main() { std::string test = "45"; int myint = std::stoi(test); std::cout << myint <

我正在测试以下链接中的
std::stoi
函数:
但我得到了一个错误:

命名空间std中没有名为stoi的成员

我该怎么办? 请告知,谢谢

S:我使用XCIDE IDE来做我的C++。

#include <iostream>
#include <string>

int main()  {
   std::string test = "45";
   int myint = std::stoi(test);
   std::cout << myint << '\n';
}
#包括
#包括
int main(){
std::string test=“45”;
int-myint=std::stoi(测试);

首先,您需要一个支持C++11的编译器,并且需要在“C++11模式”(在某些情况下)下编译

其次,如果这实际上是一个intellisense问题(看起来可能是),那么很可能是您的IDE还不支持C++11。

仅在C++11之后才可用。如果您不支持C++11,以下是基于以下内容的C++03解决方案:

std::string test=“45”;
std::istringstream is(测试);
int-myInt;
如果(是>>myInt)

std::cout如果您可以使用
stdlib.h
,那么另一种使其工作的方法是使用
atoi(const char*)


你是用
-std=c++11编译的吗?我怀疑是这样。我也不知道如何以及在哪里检查我是否用-std=c++11编译。还有,
std::strtol()
@H2CO3:是的,但这需要C风格的
char*
,它在
中。但好的一点是:)我有C++14支持,我也有同样的问题。我有C++14支持,我也有同样的问题。它显然与CLang或其组件有关。但与语言版本设置无关。@PabloAriel你可能错过了一些东西ng.虽然即使在C++17模式下,Xcode中对C++17的支持也存在差距(例如,没有
std::optional
),但C++14现在已经足够老了,我不知道缺少对
std::stoi
这样的核心的支持。问题是因为这样:
\if(((uuuu cplusplus>=201103L)&&defined(\uGlibcxx\uUse\uC99)&!defined)(_GLIBCXX_HAVE_breaked_VSWPRINTF))
但是,除了定义_GLIBCXX_USE_C99之外,没有人提到解决方案,也没有人解释为什么我应该手动添加这样的定义(虽然在我看来像是一个bug)。@PabloAriel你知道得最好。祝你好运。@PabloAriel:太好了!
std::string test = "45";
std::istringstream is(test);
int myInt;
if (is >> myInt)
    std::cout << myint << std::endl;
int myint = atoi(test.c_str());