Possible Duplicate:
Splitting a string in C++
In PHP, the explode() function will take a string and chop it up into an array separating each element by a specified delimiter.
Is there an equivalent function in C++?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Here’s a simple example implementation:
Usage:
Note: @Jerry’s idea of writing to an output iterator is more idiomatic for C++. In fact, you can provide both; an output-iterator template and a wrapper that produces a vector, for maximum flexibility.
Note 2: If you want to skip empty tokens, add
if (!token.empty()).