C++ string: Invalid pointer error

前端 未结 3 760
别跟我提以往
别跟我提以往 2021-01-28 05:43

I am getting an invalid pointer error when I call the below function. Why is this happening?

void Get(const char* value)
{
    string st(\"testing string\");
            


        
3条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-28 06:07

    I see two mistakes:

    • You assign a val.c_str() to a pointer that is local to GetVal();
    • val is destroyed at the end of GetVal(), so the pointer value would be invalid anyway.

提交回复
热议问题