How to make a variadic macro for std::cout?

前端 未结 4 1180
北恋
北恋 2020-11-27 22:05

How would I make a macro that took a variable amount of arguments, and prints its out using std::cout? Sorry if this is a noob question, couldn\'t find anything that clarifi

4条回答
  •  生来不讨喜
    2020-11-27 22:22

    You can try this one

    #include 
    
    #define LOG() std::cout
    
    int main()
    {
        LOG() << "Hello! " << "how " << "are " << "you " << std::endl;
        return 0;
    }
    

    Output:

    Hello!  how are  you 
    

提交回复
热议问题