I'm a newcomer to programming. I am learning vector
in C++. I am curious about why string s = 42;
causes error but
vector<string>vec(3);
vec[0] = 42;
does not. Thank you!
std::vector
has nothing to do with that, your sample with std::vector
is similar to
std::string s;
s = 42;
but
std::string s = 42; // Constructor: "equivalent" to std::string s = std::string(42)
is different than
std::string s;
s = 42; // assignation: s.operator =(42)
and std::string::operator=(char)
exists whereas constructor taking char
doesn't.
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