Convert string to const char

Can anybody tell me, how can I convert string to const char? I want to create a saving and a color changing system in my torpedo game.
Last edited on
String? What string? std::string?
A const char?

A char is a very small data-type. A string (of characters) has many chars. How would you compress and store a big number in a small number?


You have to explain more.
I want to convert std::string into a const char in a simple and understandable way.
1
2
3
4
const std::string str = "hello world!" ;

// http://en.cppreference.com/w/cpp/string/basic_string/c_str
const char* cstr = str.c_str() ; // pointer to const char 

Thank you! It's working. :D
keskiverto's comments still stand: that's not a const char. It's a pointer to a const char. There's a difference, and it's crucially important that you understand what that difference is.
Topic archived. No new replies allowed.