cygwin g++ std::stoi "error: ‘stoi’ is not a member of ‘std

喜你入骨 提交于 2019-12-17 07:33:08

问题


I have:

-cygwin 1.7.25 on windows 7/32bit

-g++ --version --> g++ (GCC) 4.8.2

-libstdc++.a --> gcc-g++-4.8.2-1

Tried to make a c++ Hello World:

#include <string>

int main() 
{
   std::string s = "123";
   int i = std::stoi(s);
}

compiling gives:

$ g++ -std=c++11 main.cpp
main.cpp: In function ‘int main()’:
main.cpp:6:10: error: ‘stoi’ is not a member of ‘std’
  int i = std::stoi(s);

I searched for hours but I still could not find a solution. What's the issue here?


回答1:


That's a bug, possibly an incomplete port of some library code to cygwin (it's a cplusplus11 feature) - some stuff has to be changed after all. Make sure to report it.

The solution is easy of course: #include <cstdlib> strtol(s.c_str(),0,10);

www.cplusplus.com/.../strtol

A similar mingw bug is mentioned also here

std::stoi doesn't exist in g++ 4.6.1 on MinGW




回答2:


I have the same problem yesterday. "error: 'stoi' is not a member of 'std'."

First, I made sure c++11 was enabled. Then, I updated the g++ compiler to the newest version. After that, this error disappeared.




回答3:


The compiler is not being taken seriously. On windows your best bet is to probably use visual studio, as it is always kept up to date . The bug here is that the macro defs are wrong to begin with. The problem starts from iomanip.h and iosbase . So they would have to changed all of there code. There are user made patches for this but I would not trust them at all, as they may contain even more bugs then the original copies. But it's up to you , I just stick with visual studio express edition.




回答4:


stoi works correct only on mingw64 for me. If you use Codeblocks, don't forget to check if your projects compiler is set to mingw64.



来源:https://stackoverflow.com/questions/20145488/cygwin-g-stdstoi-error-stoi-is-not-a-member-of-std

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