write a function named vowel_words() which will segregate the words starting with vowels from the "first_file.txt"
#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!
Learn more about our help with Assignments:
C++