Error when compiling yaml-cpp using MinGW: Error: 'atoi' is not a member of 'std'

Error when compiling yaml-cpp using MinGW: Error: 'atoi' is not a member of 'std'

我正在尝试在 windows 10 上编译 yaml-cpp。出于某种原因,atoi 不是 std 命名空间的一部分,我不知道哪里出了问题。谢谢!

cmake -G "MinGW Makefiles"
... (Makefile gets generated)
mingw32-make
C:\yaml-cpp-master\util\read.cpp: In function 'int main(int, char**)':
C:\yaml-cpp-master\util\read.cpp:54:11: error: 'atoi' is not a member of 'std'
       N = std::atoi(argv[i]);
           ^
util\CMakeFiles\read.dir\build.make:62: recipe for target 'util/CMakeFiles/read.dir/read.cpp.obj' failed

如果您发布源代码会更有用,但要检查一件事:确保您确实 包含 <cstdlib>.

您有两个选择,包括 atoi():

  1. #include <stdlib.h>,对 C 更友好,简称为 atoi().
  2. #include <cstdlib>,对C++更友好,可以参考atoi()std::atoi()