//Another way to split strings
#include
#include
#include
#include
using std::endl;
using std::cout;
using std::cin;
using std::string;
using std::vector;
using std::istream;
istream& getWords(istream&, vector&);
string& removeDelimeters(string&);
bool space(char);
bool not_space(char);
void display(const vector&);
int main()
{
vector words;
getWords(cin,words);
display(words);
return 0;
}
void display(const vector& vec)
{
cout<
for(vector::const_iterator iter = vec.begin();iter != vec.end();iter++)
{
cout<
}
}
bool space(char c)
{
return isspace(c);
}
bool not_space(char c)
{
return !isspace(c);
}
string& removeDelimeters(string& word)
{
string delim = ",.`~!@#$%^&*()_+=-{}][:';?>
for(unsigned int i = 0;i
{
for(unsigned int j = 0;j
{
if(word[i] == delim[j])
{
word.erase(word.begin()+i); //removes the value at the given index
break;
}
}
}
return word;
}
istream& getWords(istream& in, vector& vec)
{
typedef string::const_iterator iter;
string initial;
cout<
getline(cin,initial);
initial = removeDelimeters(initial);
iter i = initial.begin();
while(i != initial.end())
{
//ignore leading blanks
i = find_if(i,initial.end(),not_space);
//find the end of the word
iter j = find_if(j,initial.end(),space);
//copy the characters in [i,j)
if(i != initial.end())
{
vec.push_back(string(i,j));
}
i = j;
}
}