i worked on several options, cause this interested me
and the code i choose to use at the end is this,
and it account for punctuation during a word
and at the end of the sentence.
Code:
#include <iostream>
#include <ctype.h>
#include <string>
#include <sstream>
#include <vector>
using namespace std;
int main()
{
string mystring;
string mystring2;
string size;
vector<string> tokens;
vector<string>::iterator forward;
cout << "Enter a sentence : ";
getline(cin, mystring, '\n');
stringstream ss(mystring);
while(ss >> mystring2)
{
tokens.push_back(mystring2);
}
int punct = 0;
for(forward = tokens.begin(); forward != tokens.end(); forward++)
{
size = *(forward);
for(int i = 0; i != size.size()-1; i++)
{
if(ispunct(size[i]))
{
punct++;
}
}
if(ispunct(size[size.size()-1]))
{
size.erase(size.size()-1, 1);
}
if((size.size()-punct) == 5)
{
cout << size << endl;
}
punct = 0;
}
cin.get();
return 0;
}