Lets say I have a function that takes a string as a char*
void GiveMeFileName(const char* fileName)
and I call it like this
std::string folderName("C:\\myFolder\\");
GiveMeFileName((folderName + "file.dat").c_str());
As far as I can tell its working fine but as to why is a bit shaky in my head.
When I add the const char* to the std:::string, it creates a new string which I call c_str() upon to pass the pointer to the function. Is it possible that after I call the c_str() and it resolves into a pointer, the temporarily created string gets deleted and what I'm passing is in fact a pointer to the remnant of an object and thus could potentially fail?