开发者

get function parameter like streamstring

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜