Alan wrote:
How do I convert the type const char* to type char*?
The simple answer is that you can't (you can, actually, but, given the
example you reported, well... you can't).
I have an input string ("input_string") of class string. I need
to convert this to type char* in order to use it in a call to the
strtok() function.
the function strtok takes a char* because it needs to modify the string
you pass to it.
However, the .c_str() string class function
returns type const char*.
yes, because you can't modify the string content by acting on the char*
that you obtain from the c_str() method.
Now, you have two choices. This first, that is the worst one, but it's
useful if you are linking to a big chunk of c-code that was not made by
you, is to copy the content of the string object in a char* and to pass
that to strtok. The second one, that is the best one, is not to use
strtok: you can obtain the functionality of strtok by the string methods
"find_first_of" and "find_first_not_of".
The relevant code may be found below. My compiler returns the
error "invalid conversion from `const char*' to `char*'".
There is no code but it doesn't matter :)
Regards,
Zeppe