Hi all, my compiler (gcc 4.4.3 on ubuntu 10.04 64bit server) is allowing me to assign an int32_t to a std::string object. The code is as follows:
Code:
#include <stdint.h>
#include <iostream>
int main()
{
int32_t i=1000000;
std::string output;
output=i;
std::cout << output << std::endl;
return 0;
}
which outputs:
Obviously, this isn't something I should be doing, but instead something that I was allowed to mistakenly do. I would have expected a compiler error saying that no assignment operator existed for integer to std::string. Instead what I believe is happening is that the compiler is implicitly converting int32_t to char, and then assigning the char to the string.
Is this a bug with the std::string class, with the compiler, or simply something I need to be more careful to avoid?