问题
I am using codeblocks and i can't make stoi()
function work. I read other questions regarding this issue but I couldn't solve it. I checked C+11, I am using namespace std and I have the string header. I don't know how can I solve this problem.
error: 'stoi' was not declared in this scope
回答1:
found the answer on almost the same question here:
"It seems your MinGW needs a patch: Enabling string conversion functions in MinGW"
From this link you can download a .zip, than follow the instructions.
This patch enables the following list of C++11 functions and templates in the std namespace:
stoi, stol, stoul, stoll, stof, stod, stold, to_string, to_wstring
Attention, maybe you will haver errors with later versions, after using the copy/paste:
As Conduit said here:
"People should note that direct replacement of the files is not guaranteed to be safe on versions later than MinGW GCC 4.7 - use the pastebin snippets, open the files, and comment/add to the existing files. Applied as such, this still works fine on MinGW GCC 4.8.1 afai"
回答2:
I would use atoi
on the str.data()
returned value, since it is supported in all compiler versions.
回答3:
Use
#include <string>
That should work. For reference: C++11 standard plus minor editorial changes.
Or perhaps you are forgetting to prefix with std::
?
A workaround is calling .c_str()
and using the <cstdlib>
or <stdlib.h>
functions.
来源:https://stackoverflow.com/questions/23063125/stoi-codeblocks-not-working