‘stoi’ was not declared in this scope
I'm not able to comment yet :( but you could use atoi(numberGuessed.c_str())
instead of stoi()
.
Mohsen
Passionate prog-rocker, cyclist and photographer! Music Unframed host at Progrock.com, 7-10 pm (CST) every Monday! Doing my second masters, actually gonna defend in Jan 2016! Industrial Systems Engineering with the focus on vision-based control UAVs. Just have started working on real systems, and I'm currently working on a BBB to implement my already simulated controllers on the real UAV. Scary but very exciting.
Updated on June 04, 2022Comments
-
Mohsen almost 2 years
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
-
Mohsen over 8 yearsOh thank you so much it worked!
-
Lightness Races in Orbit over 8 yearsBut don't. There are very good reasons that
atoi
was supplanted. -
Mohsen over 8 years@LightnessRacesinOrbit oh really?
strtol
then? -
Lightness Races in Orbit over 8 years@Mohsen: Ideally you'd fix the problem at source and use
stoi
. Butstrtol
is a viable workaround in the meantime, yes. -
Dimitri Podborski over 8 yearsatoi has security issues right? Actually there are many ways to convert string to int. E.g. using stringstream or boost::lexical_cast etc.
-
Mohsen over 8 years@incBrain I'm gonna try them out, thanks.