Lifetime of returned strings and their .c_str() [duplicate]
问题 This question already has answers here : C++: Life span of temporary arguments? (4 answers) Closed 2 years ago . I've come across multiple instance of this pattern (with boost::filesystem only used as example): boost::filesystem::path path = ...; someFunctionTakingCStrings(path.string().c_str()); where const std::string path::string() const { std::string tmp = ... return tmp; } Although I have never experienced problem with this pattern, I was wondering when the string returned by sting() is