I need to create a string of 100 A characters.
Why does the following
std::string myString = {100, 'A'};
give different results than
std::string myString(100, 'A');
?
std::string myString = {100, 'A'};
is initialization using initializer list. It creates a string with 2 characters: one with code 100 and 'A'
std::string myString(100, 'A');
calls the following constructor:
string (size_t n, char c);
which creates a string with 100 'A's
The first initializes it to values of 100 and A
and the second calls a constructor overload of std::string
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With