The function mainCurrFile.string() returns a temporary string object, when you call std::string::c_str the returned pointer is granted to hold the right value only until the string object is available, if it get destructed, pointers keeping that location may contain irrelevant values
If you want to get a stable C string, you should copy everything in an array, not just copy the address
It seems to work so would the difference be that the string class is in scope and valid for the entire block (not temp) and the pointer it returns is to an internally allocated memory block?