user2316667 user2316667 - 1 year ago 160
C++ Question

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

I'm trying to compile yaml-cpp on windows 10. For some reason, atoi is not part of the std namespace and I can't figure out what is wrong. Thanks!

cmake -G "MinGW Makefiles"
... (Makefile gets generated)
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

Answer Source

You have two options of including atoi():

  1. #include <stdlib.h>, which is more C friendly and is referred to as simply atoi().
  2. #include <cstdlib>, which is more C++ friendly and can be referred to both atoi() and std::atoi().
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download