write an interactive menu driven c++ program that creates a text file (say text1) and then display the file. create another text file (as text) by converting each line of the 'text1' file into a lowercase string. display the contents of 'text' file.
#include<fstream>
#include<string>
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
void create_file()
{
ofstream fout("text1.txt",ios::out);
cout<<"\nFile created succesfully ";
fout.close();
}
void Enter_data(char data[])
{
ofstream fout("text1.txt",ios::out | ios::app);
fout<<data;
cout<<"\nData entered succesfully ";
fout.close();
}
void convert_to_lower()
{
string w,p,word,filename;
ifstream fin("text1.txt",ios::in);
fstream fout("text.txt",ios::in | ios::out | ios::app);
while(getline(fin,w))
{
transform(w.begin(), w.end(), w.begin(), ::tolower);
fout<<w;
}
fout.close();
fstream file;
filename = "text.txt";
file.open(filename.c_str());
while (file >> word)
{
cout << word << " ";
}
fin.close();
}
int main()
{
int n;
char data[300];
cout<<"1. Create a text file ";
cout<<"\n2. Enter data in file ";
cout<<"\n3. Copy data to another file and convert to lowercase ";
cin>>n;
if(n==1)
{
create_file();
}
if(n==2)
{
gets(data);
cin.getline(data,300);
Enter_data(data);
}
if(n==3)
{
convert_to_lower();
}
}
Comments
Leave a comment