3 ms·
No, with longer string contents the std::string will internally allocate and store on the heap, but as the containing std::string is a temporary it will be pop'
by verall 4y ago
No, with longer string contents the std::string will internally allocate and store on the heap, but as the containing std::string is a temporary it will be pop'd of the stack (stack pointer moved, which is why it works "sometimes") and its destructor called at the end of the statement (at the semicolon), freeing the heap allocated memory (which, as parents are discussing, may still work because nothing has yet overwritten the recently freed memory).
Changing it to:
call_to_C_API(std::string("path/to/file").c_str());
Makes it valid because the std::string object will live until the semicolon.