I am reading about STL string class. It is mentioned as below
STL string class chooses not to define conversion operators, but rather use the c_str() and data() methods for directly accessing the memory. The STL purposely does not include implicit conversion operators to prevent misuse of raw string pointers.
My question is
- c_str() returns const char* pointer and still user can modify string value. Am I right?
- What does the author mean by "to prevent misuse of raw string pointers"? Please explain, preferably with an example.
Thanks!
constmeans?c_str()ordata(). 2. Modifying the contents of the underlying string data without maintaining invariants. For example, by modifying via the pointer returned byc_str()ordata().