I have define a data structure
std::map<std::string, int> a;
I found I can pass const char* as key, like this:
a["abc"] = 1;
Which function provides automatic type conversion from const char* to std::string?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
std::stringhas a constructor that allows the implicit conversion fromconst char*.means that an implicit conversion such as
is allowed.
It is the equivalent of doing something like
If you wanted to disallow the implicit conversion construction, you mark the constructor as
explicit: