MENU











Tuesday, 7 January 2014

oops week14

Week 14 solutions

14 b) Write a C++ program that reads a text file and converts its
input to all lower case,producing a new file.

File(input): f1.txt
HELLO
WElcOME TO C++ PROGRAMMING

Program:

#include<iostream>
#include<fstream>
#include<ctype.h>
using namespace std;
int main()
{ 
 
 char ch;
 ifstream in("f1.txt");
 ofstream out("f2.txt");
 cout<<"\nContents of Input file \n";
 ch=in.get();
 while(in.good())
 {
  cout<ch;
  out<<char(tolower(ch));
  ch=in.get();
 }
 in.close();
 out.close();
 ifstream in2("f2.txt");
 cout<<"\nContents of Output file \n";
 cout<<in2.rdbuf();
 in2.close();
 return 0;
 
}

output:  

Contents of Input file
HELLO
WElcOME TO C++ PROGRAMMING
Contents of Output file
hello
welcome to c++ programming
  

No comments:

Post a Comment