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 <iostream>
using namespace std;
void vowelwords(string s) {
for (int i = 0; i < s.size() - 1; i++) {
if (s[i] == ' ' &&
(s[i + 1] == 'a' || s[i + 1] == 'e' || s[i + 1] == 'i' || s[i + 1] == 'o' || s[i + 1] == 'u')) {
int j = i + 1;
bool test = true;
while (test) {
cout << s[j];
j++;
if (j == s.size() || s[j] == ' ') test = false;
}
cout << '\n';
}
}
}
int main() {
freopen("first.txt", "r", stdin);
freopen("second.txt", "w", stdout);
string s;
getline(cin, s);
vowelwords(s);
return 0;
}
Example:
first.txt
hakuna matata azimjon archimedes
second.txt
azimjon
archimedes
Comments
Leave a comment