Assuming that a text file named FIRST.TXT contains some text written into it, write a function named vowelwords(), that reads the file FIRST.TXT and creates a new file named SECOND.TXT, to contain only those words from the file FIRST.TXT which start with a lowercase vowel (i.e., with 'a', 'e', 'i', 'o', 'u').
For example, if the file FIRST.TXT contains Carry umbrella and overcoat when it rains Then the file SECOND.TXT shall contain umbrella and overcoat it
#include <fstream>
#include <string>
#include <cctype>
using namespace std;
void vowelwords()
{
ifstream ifs("FIRST.TXT");
ofstream ofs("SECOND.TXT");
string word;
while (ifs) {
ifs >> word;
int ch = tolower(word[0]);
if (ch == 'a' || ch == 'e' || ch == 'i' ||
ch == 'o' || ch == 'u') {
ofs << word << ' ';
}
}
}
int main() {
vowelwords();
}
Comments
Leave a comment