Computer Science, asked by Walden5658, 1 year ago

(i) Write a C++ code which reads the contents of a text file "first_file.txt" 1 (ii) Write a function named vowel_words() which will segregate the words starting with vowels from the "first_file.txt" 2 (iii) Write a C++ code which writes the resultant words to the output file, "second_file.txt".1 Example: Content of first_file - "I am going to buy an umbrella" Output in second_file.txt - I am an umbrella

Answers

Answered by Fubuki414
18
(i) //C++ program to write and read text in/from file.
#include <iostream>
#include <fstream>

using namespace std;

int main()
{
fstream file; //object of fstream class

//opening file "sample.txt" in out(write) mode
file.open("sample.txt",ios::out);

if(!file)
{
cout<<"Error in creating file!!!"<<endl;
return 0;
}

cout<<"File created successfully."<<endl;
//write text into file
file<<"ABCD.";
//closing the file
file.close();

//again open file in read mode
file.open("sample.txt",ios::in);

if(!file)
{
cout<<"Error in opening file!!!"<<endl;
return 0;
}

//read untill end of file is not found.
char ch; //to read single character
cout<<"File content: ";

while(!file.eof())
{
file>>ch; //read single character from file
cout<<ch;
}

file.close(); //close file

return 0;
}

jacobmlp: (2)
Similar questions