开发者

get function parameter like streamstring

开发者 https://www.devze.com 2023-01-03 20:03 出处:网络
i want get to functionparameter like streamstring // Declartion foo (std::stringstream strString); // Using

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

精彩评论

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

关注公众号