本文介绍了'stoi'未在此范围中声明的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以这个错误已经解决了几次,但没有答案帮助我。我在Windows 10上使用Notepad ++和Cygwin。我的代码如下,它来自:

So this error have been addressed several times, but no answers helped me. I'm using Notepad++ and Cygwin on windows 10. My code is as follows and it's from 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 ++是我在这里的另一个话题中发现最多的upvote。这是我发现和尝试,但没有工作:
函数未声明

You see I already have applied all the suggestions in previous answered threads. Is there anything I'm missing? Do I have to start using Ming? Since Notepadd++ is the one I found with the most upvotes in another topic here. This is what I found and tried but didn't work:Function stoi not declared

推荐答案

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

I'm not able to comment yet :( but you could use atoi(numberGuessed.c_str()) instead of stoi().

这篇关于'stoi'未在此范围中声明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-21 20:23