i want get to function parameter like streamstring
// Declartion foo (std::stringstream strString);
// Using foo("Hello" << 开发者_开发知识库"world");
how to do that??
The <<
syntax used for stream insertion is achieved by the various stream classes overloading the left-shift operator (that's what the <<
is). You can overload the left shift operator for your class:
struct Example
{
Example& operator<<(int i)
{
/* use i */
return *this;
}
};
Example e;
e << 42; // calls operator<< overload
You can do it with a macro - see this answer I want to trace logs using a Macro multi parameter always null. problem c++ windows
精彩评论