by "Devdatt Lad" <dlad@[EMAIL PROTECTED]
>
Apr 30, 2008 at 10:41 AM
> i need to split the above string such that i need to get all these
> parameters.... the field widths are not fixed..i have some times four/
> three digits
> src****t ..so i cant do it with substr function...i need this in c++
Boost provides a handy utility called tokenizer that you can use to do
this.
Check out the following code. Suppose that your input is contained in a
std::string named "user_input".
// create a list to store the resulting separated words from user_input
std::list<std::string> input_args;
// use the tokenizer and specify a single space (" ") as the
char_separator
boost::tokenizer<boost::char_separator<char> > tok(user_input,
boost::char_separator<char>(" "));
// insert the results of the tokenizer into your std::list
std::copy(tok.begin(), tok.end(), std::back_inserter(input_args));
With this you don't have to worry about how many characters you have in
any
of the parts as long as you are sure that you want to separate based on
the
occurrence of white space.
Hope this helps,
Devdatt
--
[ See http://www.gotw.ca/resources/clcm.htm
for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]