C++ cout auto separator

后端 未结 7 1747
半阙折子戏
半阙折子戏 2020-12-13 17:36

I am wondering if there is way that std::cout automatically will insert some predefined value between printed sequences.

For example:

st         


        
相关标签:
7条回答
  • 2020-12-13 18:09

    Simple solution, maybe you can tweak it to use <<

    template<typename T> 
    void myout(T value) 
    { 
       std::cout << value << std::endl; 
    } 
    
    template<typename First, typename ... Rest> 
    void myout(First first, Rest ... rest) 
    { 
       std::cout << first << " ";
       myout(rest...); 
    }
    
    
    myout('a',"Hello",1,2,3,22/7.0);
    
    0 讨论(0)
提交回复
热议问题