How to write 'n' copies of a character to ostream like in python

后端 未结 4 914
半阙折子戏
半阙折子戏 2021-01-02 00:54

In python, the following instruction: print \'a\'*5 would output aaaaa. How would one write something similar in C++ in conjunction with std:

4条回答
  •  有刺的猬
    2021-01-02 01:29

    You can do something like that by overloading the * operator for std::string. Here is a small example

    #include
    #include
    std::string operator*(const std::string &c,int n)
    {
        std::string str;
        for(int i=0;i

提交回复
热议问题