Why does std::string not provide a conversion to const char*?

Automatic casts are almost always evil. If there were a cast to const char *, a std::string could be also automatically cast to other pointer types and that could lead to hard to find bugs. There is the c_str() method that returns const char * so you can still achieve what you need. Also, the typecast is not logically correct – std::string is not equivalent to const char *.

Leave a Comment