Answer to Question #72077 in C++ for Dhvani
Write a C++ code which writes the resultant words to the output file, “second_file.txt”.
Example: Content of first_file – “I am going to buy an umbrella”
Output in second_file.txt – I am an umbrella.
1
2017-12-24T10:54:07-0500
/*
* main.cpp
*
*/
#include <iostream>
#include <fstream>
#include <string>
bool check_word(const std::string& word);
int main()
{
std::ifstream in("first_file.txt");
std::ofstream out("second_file.txt");
std::string word;
if (!in) {
std::cout << "File not found!\n";
return 0;
}
while (in >> word) {
if (check_word(word)) {
out << word << " ";
}
}
return 0;
}
bool check_word(const std::string& word)
{
const char c = std::tolower(word[0]);
return c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u';
}
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++
Comments
Leave a comment