But it can't store all of the four letter words and all of the five letter words. and discard any inputs with fewer than four or more than five characters. how to do it.
the system says:
$ g++ -Wall -pedantic test111.cpp
test111.cpp: In function ‘int main()’:
test111.cpp:18:20: warning: range-based ‘for’ loops only available with -std=c++11 or -std=gnu++11
for(char &c : s.back()) c = tolower(c);
^
test111.cpp:18:41: warning: ‘c’ may be used uninitialized in this function [-Wmaybe-uninitialized]
for(char &c : s.back()) c = tolower(c);
The test111 is whatever you want to call the executable file - better than a.out IMO. I put c++14 in there - it's the current standard, put c++11 if your compiler doesn't support c++14.
#include<iostream>
#include<vector>
#include<string>
#include<cctype>
usingnamespace std;
int main ()
{
vector<string> s;
string word;
while (word != "EOF")
{
cout << "Enter your words, EOF to quit: ";
cin >> word;
if (word.length () == 4 || word.length () == 5)
{
for (size_t i = 0; i < word.size (); ++i)
word[i] = tolower (word[i]);
s.push_back (word);
}
}
cout << "Words you entered:\n";
for (size_t i = 0; i < s.size (); ++i)
cout << s[i] << '\n';
system ("pause");
return 0;
}
Output:
1 2 3 4 5 6 7 8 9
Enter your words, EOF to quit: Anna
Enter your words, EOF to quit: Lisa
Enter your words, EOF to quit: Andrea
Enter your words, EOF to quit: Cathleen
Enter your words, EOF to quit: EOF
Words you entered:
anna
lisa
Press any key to continue . . .