c++ - “stoi”未在此范围内声明

标签 c++ c++11 gcc g++ cygwin

<分区>

所以这个错误已经被解决了好几次,但没有答案对我有帮助。我在 Windows 10 上使用 Notepad++ 和 Cygwin。我的代码如下,来自 Derek Banas's 1 hour C++ tutorial :

#include <iostream>
#include <vector>
#include <string>
#include <fstream>
#include <cstdlib>
#include <sstream> 
//#include <stdlib.h>
using namespace std;
int main(){
    string numberGuessed;
int intNumberGuessed = 0;
 do {
    cout << "Guess between 1 and 10: ";
     getline (cin,numberGuessed);
     intNumberGuessed = stoi(numberGuessed);
    cout << intNumberGuessed << endl;
 } while (intNumberGuessed != 4);
   cout << "You Win" << endl;
    return 0;
}

这是我得到的错误:

$ g++ -std=c++11 -static ctut.cpp
ctut.cpp: In function ‘int main()’:
ctut.cpp:15:43: error: ‘stoi’ was not declared in this scope
      intNumberGuessed = stoi(numberGuessed);

您看,我已经应用了之前已回答主题中的所有建议。有什么我想念的吗?我必须开始使用 Ming 吗?因为 Notepadd++ 是我在此处的另一个主题中发现的获得最多赞成票的那个。这是我发现并尝试但没有用的: Function stoi not declared

最佳答案

我还不能评论 :( 但你可以使用 atoi(numberGuessed.c_str()) 而不是 stoi()

关于c++ - “stoi”未在此范围内声明,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34580830/

相关文章:

c++ - 基本 RValue 方法返回

c++ - 使用自动变量打印 vector 的内容

c - 使 C 预处理器忽略某些#include 指令

c++ - 创建带有精美细边框的文本字段。 Winapi

c++ - 模板函数中的多态性

c++ - 按值传递认为参数是const

c++ - 自动返回类型匹配 void

c++ - 未声明未使用的变量。 gcc 取笑我?

c++ - 二叉搜索树删除两个 child

C 库的 C++ 包装器作为共享库