c++ - Why insertion operator is printing address instead of string? -
i have simple lines of code, using insertion operator <<
show hello world string. if use a operator b should result a.operator(b);
try same thing insertion operator , in output got address of string, rather actual string.
std::cout<<"hello world"<<std::endl; std::cout.operator<<("hello world").operator<<(std::endl);
output:
hello world
0120cc74
i using visual studio.
does operator conversion has problem?
std::cout<<"hello world"<<std::endl;
use overloaded output operator const char*
, free function, not member function.
std::cout.operator<<("hello world").operator<<(std::endl);
use overloaded output operator const void*
, since const char*
implicitly convertible const void*
.
you can @ member overloads here , free overloads here
Comments
Post a Comment