The constructor of std::string is called here. You can understand the form of this constructor as std::string(count, ch);, that is, the first parameter is the number of repeated characters, and the second parameter is the character used for repetition. . For example:
is a constructor of string. The first parameter 10 represents how many characters there are, and the second parameter '9' represents the initial value of these characters.
Similarly, vector<int> arr(100, 0) represents a 100 with a size of 0 and all elements are initialized to vector.
Principle of simplification
The constructor of
std::string
is called here. You can understand the form of this constructor asstd::string(count, ch);
, that is, the first parameter is the number of repeated characters, and the second parameter is the character used for repetition. . For example:The actual principle
Actually
std::string
is the alias (std::basic_string
) of this template classtypedef
under specific parameters:And the real constructor is
The third parameter has a default value and does not need to be provided when calling, thus converting it into
std::string(count, ch);
.http://en.cppreference.com/w/cpp/string/basic_string/basic_string
is a constructor of
string
. The first parameter10
represents how many characters there are, and the second parameter'9'
represents the initial value of these characters.Similarly,
vector<int> arr(100, 0)
represents a100
with a size of0
and all elements are initialized tovector
.