Click here to Skip to main content
15,936,979 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi How can i break a file into tokens.
Is there any method to parse the input file on basis of strings ?
Updated 23-Sep-11 7:49am

You can use "strtok" or "strtok_s" to tokenize the string.
Share this answer
Take some time to learn about string[^]s.
Share this answer
Well you have a couple of options to choose from:

1. Use the strtok/wcstok[^] functions. You can aplay them to strings by calling c_str, but it is a bit of a pain really.

2. You can get yourself a tokenizer written for strings like this one here at CP C++ String Toolkit (StrTk) Tokenizer[^]. I just picked this one at random - haven't used it so you will have to give it a go and see if you like it. If not - you can always use the article to help you create your own solution.

3. You can use the Boost tokenizer. This is pretty close to the 2nd solution, but, you know, Boost :) Boost::Tokenizer[^]

Having said all of that I have to admit I only use the first approach. It has grown on me over the years I guess :) Best of luck to you!
Share this answer
ShilpiP 20-Sep-11 2:17am    
Perfect Answer !! +5

Take a look at the following link on strtok[^]
Share this answer
ShilpiP 20-Sep-11 2:18am    
Correct +5 !! I am late :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900