im having a problem with ostream, I wrote a very simple macro that should print its parameters.
Please see the sample code below:
#define LOG Message(__FILE__, __LINE__,__func__)
class Message : public std::ostringstream
{
public:
Message(const char *param1, int param2, const char *param3)
{
*this<<param3<<"("<<param1<<":"<<param2<<")";
}
~Message()
{
*this<<endl;
cout<< rdbuf()->str();
}
};
int main()
{
int integer = 1;
string str = "XYZ";
LOG<<integer<<"DEBUGLOG1: "<<str<<" "<<integer;
return 0;
}
The problem is that I am using:
LOG << "LOG1: " << str << " " << integer;
The output prints the address * of the char constant * "LOG1:", not the value.
But, if I use:
LOG << integer << "DEBUGLOG1: " << str << " " << integer;
The output works fine by printing an integer value and a char value.
he looks instead of using ostream& operator<< (ostream& out, const char* s );
uses ostream& operator<< (const void* val);?
Can someone shed some light on what can be done to overcome this overload, please?
Thanks in advance
source
share