stoi() CodeBlocks not working

烈酒焚心 提交于 2019-12-12 09:53:48

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!