It returns a pointer to const data, otherwise, you could access the private data in the string and alter it.....not good!!!
Code:
#include<iostream>
#include<cstring>
#include<string>
int main(){
std::string name = "endo!!";
std::cout << name << std::endl;//ok so far
/*now for something awful!*/
char* ptr = const_cast<char*>(name.c_str());//You could..
/*but then!!!! Agh!!!!!*/
strcpy(ptr,"Fordy!");//surely not!!!!!
std::cout << name << std::endl;//nasty!!!!
return 0;
}
Best bet...assign it to a const char*...you shouldnt expect to change that char array....so it can safely be const...
If you want to alter a copy of the string...then use the normal string copying methods
Code:
char copy[10];
strcpy(copy,name.c_str());
or something....