I've got a const char *
returned from a processing function, and I'd like to convert/assign it to an instance of std::string
for further manipulation. This seems like it should be straight-forward, but I've not been able to find any documentation showing how it should be done. Obviously, I'm missing something. Insights appreciated.
We can convert a char to a string object in java by using the Character. toString() method.
const char* const says that the pointer can point to a constant char and value of int pointed by this pointer cannot be changed. And we cannot change the value of pointer as well it is now constant and it cannot point to another constant char.
std::string::copyCopies a substring of the current value of the string object into the array pointed by s. This substring contains the len characters that start at position pos. The function does not append a null character at the end of the copied content.
std::string
has a constructor fromconst char *
.This means that it is legal to write:
const char* str="hello"; std::string s = str;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With