+ 1
itoa()
Cannot use itoa() function: ..\Playground\:7:10: error: 'itoa' was not declared in this scope itoa(i, size, 10); ^
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
+ 8
Did you include stdlib?
+ 1
@Helioform Yes I did include <stdlib.h> / <cstdlib> but compiler does not recognise the function.
@Hatsy Rei I see. Thanks for suggestion.
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)