c++11 to_string to working with code::blocks -std=c++11 flag already selected

12,328

Solution 1

MinGW-w64 added support for the necessary functionality since GCC 4.8, so make sure you are using at least version 4.8 GCC from MinGW-w64.

You can get one from here, although Code::Blocks should come with a TDM GCC toolchain which should work if it's the latest (because it's GCC 4.8.1 at the time of writing).

Solution 2

i also encounter this error in codeblocks-13.12mingw-setup-TDM-GCC-481.exe(built on 27 Dec 2013). it seems a bug with tdmgcc4.8.1. maybe the newest tdmgcc whill fixed it. https://stackoverflow.com/questions/21626866/c-elipse-cdt-getting-to-string-was-not-declared-in-this-scope-with-tdm-gcc-6 the reason of above list should be the same as ours.

============================== The std::to_string functions are guarded by !defined(_GLIBCXX_HAVE_BROKEN_VSWPRINTF). MinGW defines this symbol as 1 in its os_defines.h, so you know, we cannot use it in mingw.

Share:
12,328
Montana
Author by

Montana

Updated on July 26, 2022

Comments

  • Montana
    Montana almost 2 years

    this is the code i am trying to compile, got it from another forum somewhere.

    // to_string example
    
    #include <iostream>   // std::cout
    
    #include <string>     // std::string, std::to_string
    
    
    int main ()
    
    {
    
      std::string pi = "pi is " + std::to_string(3.1415926);
    
      std::string perfect = std::to_string(1+2+4+7+14) + " is a perfect number";
    
      std::cout << pi << '\n';
    
      std::cout << perfect << '\n';
    
      return 0;
    
    }
    

    I am getting the error: 'to_string' is not a member of 'std'

    I have read in other forums to select the flags "Have g++ follow the c++11 ISO language standard [-std=c++11]" and i have and it still doesn't work.

    Any help would be greatly appreciated

    I am using the GNU GCC Compiler and code::Blocks 12.11