Hello,
I need some help with my homework assignment fir my C++ class, here is a description of the assignment:
Write a program that reads this file and finds the longest word that contains only a single vowel (a,e,i,o,u). Output this word (there will actually be several ties for the longest word. Your program only needs to output one of these words).
I managed to write a program that will find the longest word, I am having issues finding a single vowel.
At first I thought I might need to use a "for statement" to do this, but I could not figure out a way to make it work.
Here is the code that I have so far:
#include <iostream>
#include <fstream>
#include <cstdlib>
std::string word;
std::string longest_word;
using namespace std;
int main()
{
ifstream inStream;
string word;
string longest_word;
int size;
inStream.open("words.txt", ifstream ::in);
while(inStream) {
inStream >> word;
if (word.size () > longest_word.size ())
longest_word = word;
}
cout << longest_word << endl;
inStream.close( );
system("PAUSE");
return EXIT_SUCCESS;
}
Would it even be possible to use a "for loop" for this program?