This is very strange. itoa();
seems to create an infinite loop.
for(int i = 0; i < 10; i++)
{
char buffer[1];
itoa(i, buffer, 10);
std::cout << buffer;
}
Why on earth does it do that? I've tried using different variables than i
, numerical values without variables (i.e. itoa(1, buffer, 10);
), it still keeps ending up in an infinite loop.
I've tried to google without much success, I found an old mail about it here.
I am using Windows XP 32 bit and Code::Blocks (with GCC) as a compiler.
Does anyone know what's wrong? Thanks in advance.
itoa
null-terminates the string it produces, but you haven't madebuffer
large enough to hold the terminating NUL character. Try: