I have seen two methods to accomplish this in C++11:
std::string foo("Hello World");
// Option #1
const_cast<char*>(foo.c_str());
// Option #2
&foo[0]
Which one is the correct or most preferred method? Is there maybe an option #3 or more? My understanding is that std::string::data()
does not guarantee null termination (which is important here), so I didn't list that as a valid option.