How does strtok_s tokenize a char*?
It seems to have modified the original string that I wanted to split specifying tokens.
how does it return back a substring if i开发者_如何转开发t can't copy from memory?
I'm also looking for an alternative that accepts a const char*
Or doesn't modify the orignal string.
Or is it safe to just const_cast
the string to remove the const property and let it be handled by strtok_s(char*, const char*, char**)
.?
strtok_s
et al do modify the strings passed in, so no, you can't pass in a const_cast
d constant string. What it does is if it finds a delimiter, it replaces that delimiter with a NUL terminator to separate the string into two pieces. It then returns a pointer to the first part, which is now the desired null-terminated token.
If you don't want to modify the original string, you can always copy it first and then strtok_s
it.
精彩评论