Answer to Question #73214 in C++ for Nikesh Hembrom

Question #73214
write a function named vowel_words() which will segregate the words starting with vowels from the "first_file.txt"
1
Expert's answer
2018-02-06T08:23:07-0500
#include <fstream>
#include <iostream>
#include <string>
#include <vector>
using namespace std;


void vowel_words()
{
ifstream in("first_file.txt");
if(!in.is_open())
{
cout << "Can't open file\n";
exit(0);
}
vector<string> vwords;

while(true)
{
string word;
getline(in, word, ' ');

if(!in) break;

char f;
if(!word.empty())
f = word.front();
if(f == 'a' || f == 'e' || f == 'i' || f == 'o' || f == 'y' || f == 'u'
|| f == 'A' || f == 'E' || f == 'I' || f == 'O' || f == 'Y' || f == 'U')
vwords.push_back(std::move(word));

}

for(const auto& x : vwords)
cout << x << endl;
}



int main()
{
vowel_words();
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS