Why "itoa" function doesn't work with C++11 ISO standard?

Hey guys. I have this pretty simple code here:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#include <iostream>
#include <cstdlib>

using namespace 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.
Last edited on
Ah, I get it now. I didn't know there was such a function for strings, though, when I asked my school professor about it he told me to use itoa.

Thank you :)
Topic archived. No new replies allowed.