Search code examples
c++c++11dev-c++

C++ to_string not a member of std on Dev C++


#include <iostream>
#include <string>

using namespace std;

int subtract(int num1, int num2)
{
    return num1-num2;
}

int main() 
{
    cout << "Input the number to subtract from: ";
    int num1;
    cin >> num1;
    cout << "\nInput the number to subtract from " + std::to_string(num1);
    int num2;
    cin >> num2;
} 

No other posts have helped me at all. All of them just say you have to have C++11 enabled, but I already do.

[Error] 'to_string' is not a member of 'std'


Solution

  • Make sure you have passed flag -std=c++11 or -std=gnu++11 to the compiler. This should be set somewhere in the project options. Otherwise, compiler that is included with Dev-C++ might operate by default in the c++98 mode, which, obviously, doesn't have std::to_string(), i.e. that is correct for C++98, which you likely have without that option.