+ 1

itoa()

Cannot use itoa() function: ..\Playground\:7:10: error: 'itoa' was not declared in this scope itoa(i, size, 10); ^

31st Mar 2017, 2:18 AM
Autumn
Autumn - avatar
4 Answers
+ 17
Yeah, I also realised this with C.Playground sometime ago. Function itoa() isn't defined in ANSI-C, and isn't part of C++ standard, but is supported by some compilers. Apparently, C.Playground does not. itoa() is used to put integers into character arrays. The usefulness of this function is that the programmer gets to specify number base conversion, which makes this a supreme tool for conversion of that field. If you simply want to convert integer to string (character array), you may look into <sstream>, which provides a fairly easy way to that, and it is in the C++ standard. https://code.sololearn.com/cGmaciug1dkk/?ref=app
31st Mar 2017, 2:26 AM
Hatsy Rei
Hatsy Rei - avatar
+ 8
Did you include stdlib?
31st Mar 2017, 2:20 AM
Karl T.
Karl T. - avatar
+ 1
@Helioform Yes I did include <stdlib.h> / <cstdlib> but compiler does not recognise the function. @Hatsy Rei I see. Thanks for suggestion.
31st Mar 2017, 2:33 AM
Autumn
Autumn - avatar
0
It seems that the compiler doesn't recognize the "itoa" function, what I find weird because in school I learned it in c++ and in practice it's not working for me. Any suggestions for a function that replaces the "itoa" function which works in c++ vs 2017? For one digit input I can see how to convert it through the ASCII value but how would you convert a longer number? (I'll mention that I need to avoid the <string> library for studying reasons)
5th Feb 2019, 2:19 AM
Josh
Josh - avatar