Multiplying a string by an int in c++
问题 What do I have to do so that when I string s = "."; If I do cout << s * 2; Will it be the same as cout << ".."; ? 回答1: No, std::string has no operator * . You can add (char, string) to other string. Look at this http://en.cppreference.com/w/cpp/string/basic_string And if you want this behaviour (no advice this) you can use something like this #include <iostream> #include <string> template<typename Char, typename Traits, typename Allocator> std::basic_string<Char, Traits, Allocator> operator *