[Tutor] what is the equivalent function to strtok() in c++

Dave Angel davea at ieee.org
Mon Jan 11 08:49:06 CET 2010


sudhir prasad wrote:
> hi,
> what is the equivalent function to strtok() in c++,
> what i need to do is to divide a line into different strings and store them
> in different lists,and write them in to another file
>
>   
If your tokens are separated by whitespace, you can simply use a single 
call to split().  It will turn a single string into a list of tokens.

line = "Now   is the time"
print line.split()

will display the list:
['Now', 'is', 'the', 'time']

HTH
DaveA




More information about the Tutor mailing list