Author Topic: Error stoi is not a member of std  (Read 36995 times)

Offline lesterclayton

  • Single posting newcomer
  • *
  • Posts: 3
Error stoi is not a member of std
« on: March 11, 2014, 02:16:11 pm »
According to http://en.cppreference.com/w/cpp/string/basic_string/stol, std::stoi is part of <string>, but when I try to compile the following code:

Code: [Select]
#include <iostream>
#include <string>

int main()
{
    std::string str1 = "45";
    std::string str2 = "3.14159";
    std::string str3 = "31337 with words";
    std::string str4 = "words and 2";

    //The error occurs on the next line
    int myint1 = std::stoi(str1);
    int myint2 = std::stoi(str2);
    int myint3 = std::stoi(str3);


    std::cout << "std::stoi(\"" << str1 << "\") is " << myint1 << '\n';
    std::cout << "std::stoi(\"" << str2 << "\") is " << myint2 << '\n';
    std::cout << "std::stoi(\"" << str3 << "\") is " << myint3 << '\n';
}

I get the error "error: 'stoi' is not a member of 'std'"

I did some Googling and found that I apparently need the -std=c++11 flag to enable this feature, but I have this checkbox checked in my GNU GCC Compiler page, as follows:



Can anybody shed some more light on this issue for me please?

Using Code::Blocks 12.11 with mingw32-gcc (tdm-1) 4.7.1

Offline stahta01

  • Lives here!
  • ****
  • Posts: 6720
    • My Best Post
Re: Error stoi is not a member of std
« Reply #1 on: March 11, 2014, 02:21:38 pm »
http://wiki.codeblocks.org/index.php?title=FAQ-Compiling_%28errors%29#Q:_How_do_I_troubleshoot_a_compiler_problem.3F

Edit1: Post the full "Build Log" or it is NOT possible to help you.

Edit2: Posting the exact error message is normally helpful, also.

Edit3: Looking like a Compiler Problem.

Tim S.
« Last Edit: March 11, 2014, 02:39:27 pm by stahta01 »
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 32 bit.
On Debian Stretch, compiling CB Trunk against wxWidgets 3.0.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline lesterclayton

  • Single posting newcomer
  • *
  • Posts: 3
Re: Error stoi is not a member of std
« Reply #2 on: March 11, 2014, 02:32:12 pm »
Thanks for the reply.

Here is the Debugged Build Log

Quote
-------------- Build: Debug in Stoi Example (compiler: GNU GCC Compiler)---------------

mingw32-g++.exe -Wall -fexceptions  -g  -std=c++11    -c "Z:\stuff\C++ Projects\Lesson 10\Stoi Example\main.cpp" -o obj\Debug\main.o
Z:\stuff\C++ Projects\Lesson 10\Stoi Example\main.cpp: In function 'int main()':
Z:\stuff\C++ Projects\Lesson 10\Stoi Example\main.cpp:12:18: error: 'stoi' is not a member of 'std'
Z:\stuff\C++ Projects\Lesson 10\Stoi Example\main.cpp:13:18: error: 'stoi' is not a member of 'std'
Z:\stuff\C++ Projects\Lesson 10\Stoi Example\main.cpp:14:18: error: 'stoi' is not a member of 'std'
Process terminated with status 1 (0 minutes, 0 seconds)
3 errors, 0 warnings (0 minutes, 0 seconds)

I was under the impression that I had posted the exact error message, which is "error: 'stoi' is not a member of 'std'", but thanks for the tip.

Offline stahta01

  • Lives here!
  • ****
  • Posts: 6720
    • My Best Post
Re: Error stoi is not a member of std
« Reply #3 on: March 11, 2014, 02:49:26 pm »
Looks like a Compiler problem to me; I suggest looking in the TDM thread or website for known issues.

Edit: Known issue in MinGW GCC 4.6 according to this thread http://stackoverflow.com/questions/8542221/stdstoi-doesnt-exist-in-g-4-6-1-on-mingw

Edit2: http://stackoverflow.com/questions/20145488/cygwin-g-stdstoi-error-stoi-is-not-a-member-of-std

Tim S.
« Last Edit: March 11, 2014, 03:15:31 pm by stahta01 »
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 32 bit.
On Debian Stretch, compiling CB Trunk against wxWidgets 3.0.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline lesterclayton

  • Single posting newcomer
  • *
  • Posts: 3
Re: Error stoi is not a member of std
« Reply #4 on: March 11, 2014, 03:46:34 pm »
Thank you :)