Write a c++ program to implement the following . 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 the lowercase vowel (a,e,i,o,u).
#include <fstream>
#include <string>
#include <cctype>
using namespace std;
void vowelwords()
{
ifstream in("first.txt");
ofstream out("second.txt");
string w;
while (in) {
in >> w;
int c = tolower(w[0]);
if (c == 'a' || c == 'e' || c == 'i' ||
c == 'o' || c == 'u') {
out << w << ' ';
}
}
}
int main() {
vowelwords();
}
Comments
Leave a comment