I am trying to convert a char pointer to a string pointer but I am not sure if I am doing it correctly. I just wanted to post what I was trying and see if it was correct.
For context, I have a char * called ent->d_name and I need that to become a string *. This is what I have been doing:
std::string arg = std::string(ent->d_name); std::string * arg_p = &arg; Command::_currentCommand->insertArgument(arg_p); The insert command function takes a string pointer.
string *. If you are using a library that does so, the person who designed the library almost certainly didn't know what they were doing, and you should not be using that library. And you cannot directly convert achar *to astring *.Commandthingie is going to do witharg_p. Does it just use it right away or does it store it somewhere? Is it guaranteed thatargdoes not get destroyed before theCommandaccesses the pointer you gave it?string*. It's more likely you want astring, and probably want to create a new one instead fo casting...std::string arg = std::string(ent->d_name); Command::_currentCommand->insertArgument(&arg);-- Why the intermediate pointer variable, when you could have just passed the address ofarg?