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

后端 未结 5 481
孤街浪徒
孤街浪徒 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:33

    Pass a memory location to foo() and have foo modify that:

    void foo (string* _out_newStr)
    {
        _out_newStr->assign("dummy string"); //This is wrong -> _out_newStr = "dummy string";
        return;
    }
    

    Then when you are using the "c_str()" function of the string object you will return a const char* value, as already pointed out.

提交回复
热议问题