Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Assign double to std::string -- no compile error? [duplicate]

Tags:

Why isn't the compiler complaining about this code:

#include <string>
#include <iostream>

int main()
{
   std::string a;
   a = 2.3;
   std::cout << "A:" << a << std::endl;
   return 0;
}

GCC, MSVC don't seem to be concerned about this at all, even though it is clearly wrong and doesn't actually work anyway!

The output is:

A:

OUCH ! Lead to an undetected error in my program.