Here's a very wild guess, though I could be mislead by the contradictory and incomplete information given:
- I assume you have a function that takes a
char*
as parameter, e.g. like the my_func
provided in the question.
- I further assume you try to dereference a
const_iterator
of some kind, ultimately getting a reference to a const string, and call c_str()
on it.
- The next assumption is that you want to pass the result of that call to your function.
That would look somewhat like this:
void my_func(char*);
int main() {
std::map<int, std::string> theMap;
// ...
std::map<int, std::string>::const_iterator cit = theMap.find(3);
assert(cit != theMap.end());
my_func(cit->second.c_str()); //problematic line
}
In this case, you should get a compilation error, because c_str()
returns a const char*
. while your function expects a char*
, and the two are not compatible.
However, my assumptions have several flaws:
- The error should be about the conversion from
const char*
to char*
and should not have to do anything with basic_string
- It has nothing to do with
regexec
(but neither has your example code)
- It cannot lead to segfaults, since it does not compile (but that contradiction is already present in your question)
If you shed some more light on the question, I will be able to give more specific hints on what is going wrong.
carcode and tell us exactly *what* is wrong with it, i.e. provide the error messages. – Arne Mertz Jun 03 '14 at 14:41