Apr 30, 2018 at 6:17pm UTC
Is any funciton to convert string to char*? not to const char*
Apr 30, 2018 at 10:29pm UTC
In C++17 you can use str.data()
, otherwise you can use &str[0]
.
May 1, 2018 at 11:17am UTC
@OP: What do you mean by "convert"?
- Do you want a non-const pointer to the actual character storage within the std::string object?
- Do you want to generate a new
char array, that contains a copy of the character data from the std::string object?
What is it you want to do with that pointer, that it needs to be non-const?
EDIT: *Sigh* this is a duplicate of
http://www.cplusplus.com/forum/general/236064/ . Please DON'T make multiple threads for the same question. You just waste people's time.
Last edited on May 1, 2018 at 11:20am UTC
May 1, 2018 at 1:19pm UTC
doing as Peter87 said is fine until you change its length. If you need to change its length, you need to copy it out to a C string and leave the object alone.