how to set char * value from std string (c_str()) not working

后端 未结 5 506
孤街浪徒
孤街浪徒 2020-12-20 22:38

i dont know but this not working for me im getting garbege value when i try to set char * value from function that returns std string :

string foo()
{
  st         


        
5条回答
  •  伪装坚强ぢ
    2020-12-20 23:34

    The code-snippet invokes undefined behavior, because the temporary std::string created from the call is destroyed at the end of the expression but cc which is pointing to the destroyed object, is still used even after that.

提交回复
热议问题