‘stoi’ was not declared in this scope [duplicate]

2019-05-03 17:24发布

This question already has an answer here:

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;
}

and this is the error I get:

$ 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);

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

1条回答
迷人小祖宗
2楼-- · 2019-05-03 18:22

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

查看更多
登录 后发表回答