I am using the
undefined reference to `itoa'
collect2: ld returned 1 exit status
snprintf, it is more portable than
itoa is not part of standard C, nor is it part of standard C++; but, a lot of compilers and associated libraries support it.
char* buffer = ... allocate a buffer ... int value = 4564; sprintf(buffer, "%d", value);
char buffer; int value = 234452; snprintf(buffer, 10, "%d", value);
Both functions are similar to
fprintf, but output is written into an array rather than to a stream. The difference between
snprintf is that
snprintf guarantees no buffer overrun by writing up to a maximum number of characters that can be stored in the