#include <iostream>
#include <cstdlib>
usingnamespace std;
int int_length(int a){ //calculates the
int b=1; //number of digits
while(a/=10) //of an integer
b++;
return b;
}
int main()
{
int a,b;
cout<<"enter a and b:\n";
cin>>a>>b;
char ac[int_length(a)];
itoa(a,ac,10);
cout<<ac;
return 0;
}
However, when I turn on the "Have g++ follow the C++11 ISO language standard" in the compiler options (which I needed earlier to use 'tuple' objects) my code won't compile. I get the "itoa was not declared in this scope" error.
But when I turn it off, the code works.
Why is that so?
Does C++11 not support cstdlib, and if so, why?
There is no itoa function in C or C++ standard libs. You are probably using nonstandard extension which was disabled when you explicitely told to adhere to the specific standard. If you want to output something in c-string, use sprintf/snprintf: http://en.cppreference.com/w/cpp/io/c/fprintf
However in C++ there is no reason why you shouldn't use std::string class and std::to_string family of functions.