Store c_str() as char *
c++, c-str, constants, string
Solution
The problem you are having is that `c_str()` returns a buffer that can not be modified (`const`), while `stem()` may modify the buffer you pass in (not `const`). You should make a copy of the result of `c_str()` to get a modifiable buffer.
The page http://www.cplusplus.com/reference/string/string/c_str/ has more information on the C++ 98 and 11 versions. They suggest replacing `char * b = s.c_str();` with the following:
char * b = new char [s.length()+1];
std::strcpy (b, s.c_str());
Problem
I'm trying to use the function with the following declaration: `extern int stem(struct stemmer * z, char * b, int k)1` I'm trying to pass a C++ string to it, so I thought I'd use the `c_str()` function. It returns `const char *`. When I try to pass it to the `stem()` function, I get this error: `error: invalid conversion from 'const char*' to 'char*' [-fpermissive]`. How can I store the result of c_str() such that I can use it with the `stem` function? Here is the code I'm running: ``` struct stemmer * z = create_stemmer(); char * b = s.c_str(); int res = stem(z, b, s.length()); //this doesn't work free_stemmer(z); return s.substr(0,res); ```