I would say boost/algorithm/string/split.hpp is what u need. its still no standart functions , but a lot of the boost libs will become standart in the 0x10 c++ standart and i m pretty sure that the string-algo lib will...
btw boost is so powerfull u should have a look or even learn to handle some parts.
like boost::split
the function gets a sequence,a collection and a prdicate, and an so called token compress mode type, but u dont need that one.
so for your purposes it would look like this
template<typename SequenceSequenceT, typename CollectionT,
typename PredicateT>
SequenceSequenceT &
split(SequenceSequenceT &, CollectionT &, PredicateT,
token_compress_mode_type = token_compress_off); or shorter:
split(SequenceSequenceT &, CollectionT &, PredicateT);
where for example the collections is a std::string and the sequence is a std::vector<std::string>
id just wrote this little testmain. i think its exactly what you ask for:
#include<iostream>
#include<string>
#include<vector>
#include<boost/algorithm/string.hpp>
#include<algorithm>//test output
#include<iterator>// test output
int main() {
std::string line("hallo-this-is-a-string");
std::vector<std::string> result;
boost::split(result,line,boost::is_any_of("-"));
// puts the result of a split of line into the
// result container without things that match to the prediate
//"-" or in your case " "
if(!result.empty())
std::copy(result.begin(),result.end(),std::ostream_iterator<std::string>(std::cout,"\n"));
return 0;
} so here is the compare:
your wish:
function(container,string,delim);
solution:
split(container,string,predicate); where predicate is the delim...
as you can see its exactly the same u ask for. but since it is a template u
can use it on every containers convertable to each other.