<p>I have a string that I would like to tokenize.
But the C <code>strtok()</code> function requires my string to be a <code>char*</code>.
How can I do this simply?</p>

<p>I tried:</p>

<pre><code>token = strtok(str.c_str(), " "); 
</code></pre>

<p>which fails because it turns it into a <code>const char*</code>, not a <code>char*</code></p>

Duplicate the string, tokenize it, then free it.
```
```
char *dup = strdup(str.c_str());
token = strtok(dup, " ");
free(dup);
```
```