I am new to C++. I want to write a function called get_token()
that will return the next token. For example str="123 456 789";
after I call get_token(str)
, it will return 123
, then if I call get_token(str)
again, it will return 456
.
void get_token(char str[]) {
char* token = strtok(str," ");
while (token) {
cout << "Token: "<< token << endl;
token = strtok(NULL, " ");
}
}
Can someone help me with this function? And write it to char* get_token(...)