Please click on 1-2 Ads to keep this website's Study Material FREE and regularly Updated.

Program 21: Write a C++ program to convert all ‘m’ to ‘t’ in a file.

#include<fstream>
#include<iostream>

using namespace std;
int main()
{
	fstream f ,fin;
	f.open("C:\\Users\\Sandeep\\Desktop\\file1.txt",ios::in|ios::out|ios::binary);
	fin.open("C:\\Users\\Sandeep\\Desktop\\file2.txt",ios::in|ios::out|ios::binary);
	char ch;

	if(!f)
		cout<<"file doesnt exist ";
	else
	{
		while(f)	
		{ 
			f.get(ch);
			if(ch=='m'||ch=='M')
			fin<<"t";
			else
			fin<<ch;		
		}
	}	

	f.close();
	fin.close();
	return 0;
}



If you have any suggestion or found any error in the above program, then do let us know at [email protected] or just comment below.