I have a string "path" that I'm trying to assign to the variable "src". But when I try to do this, I get the error "Array must be initialized with a brace-enclosed initializer". Can someone tell me what I have to do? How can I convert a string into a char* ?
First, you declared an array of pointers to chars. You just want an array of chars, so you can get rid of the asterisk. Apart from that, there is no implicit conversion from std::string to char*, though there is the other way round (due to its constructors and assignment operators). Basically, you need to specify that you want to convert the std::string into a char*. For this, the best way (and the most common way) is to use the c_str() member function, which returns the underlying char* from the string:
@NT3:
When I try your solution, there is still the same error message: "Array must be initialized with a brace-enclosed initializer"
@RabMac:
When I try your solution, there is an other error message: "Cannot convert 'std::string {aka std::basic_string<char>}' to 'char*' in initialization"
I need the string as an array of char because the function I want to call needs an array of char.
I don't know what I just did with this line (copied it from the internet), but it works. To be honest, I don't have the least idea what I am doing here. :-P
But it seems to work.