I have the following code to convert a string to char :
string tempLine = dataLine[studentIndex];
char str = tempLine.c_str();
but this line returns an error : ” a value of type “constant char *” cannot be used to initialize an entity of type “char”.
How can I fix this issue??
should be:
Note that you’re not supposed to change the content of the string. Generally, its not a good way to work with C++ strings. If you really have to fully convert a C++ string to C string – allocate memory and use
strcpyto copy data, don’t use the C++ string buffers directly.edit for your request in the comments: Look here for C++ learning resources.