I recently migrated from C to C++, and there's a little confusion about strings. Strings just aren't what they used to be any more, as in, not just char arrays with a terminating '\0'. I haven't found a real answer to this question, so how far can you treat the std::string class like C-Strings?
For example: If I know there's a number somewhere in a string, let the string be ireallylike314
, in C I could use strtol(string + 10, NULL, 10)
to just get that number.
And, if this doesn't work, is there a way to use std::string like C-strings?
Use c_str()
.
strtol(string.c_str() + 10, NULL, 10);
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