Converting from std::string to char * in C++

c++, type-conversion, visual-studio-2010

Solution

Use

std::string bla("bla");
char* blaptr = &bla[0];

This is guaranteed to work since C++11, and effectively worked on all popular implementations before C++11.

If you need just a `const char*`, you can use either `std::string::c_str()` or `std::string::data()`

Problem

I'm using VS2012/C++, I need to convert a std::string to char * and I can't find any material online giving any guidance on how to go about doing it. Any code examples and advice will be greatly appreciated.

Original source

Related problems