Copy of const char * using std::string constructor

前端 未结 5 506
鱼传尺愫
鱼传尺愫 2021-01-15 09:36

is this code ok?

void SomeClass :: foo(const char * _name) {
     //name is of type const char *
     name = std::string(_name).c_str();
}

5条回答
  •  佛祖请我去吃肉
    2021-01-15 09:52

    I vote for strcpy. Why complicate simple things?

    Or even better - since you'll obviously need to use it later, why not convert it to a std::string and just use that afterwards, forgetting about all those char *?

提交回复
热议问题