prowessapps.in File Handling Programs in C++

#include< iostream>
#include< fstream>
using namespace std;
class Test {
 public:
 void write() {
  char c;
  char name[10];
  ofstream out;
  cout<<"Enter File Name: ";
  cin.getline(name,10);
  out.open(name,ios::out);
  if(out.is_open()) {
   cout<<"Enter data to save till @\n";
   while((c=getchar())!='@') {
    out<< c;
   }
   cout<<"Written Successfully";
  }
  else {
   cout<<"File can't created";
  }
  out.close();
 }
};
int main() {
 Test t;
 t.write();
 return 0;
}
OUTPUT
Enter File Name: apps.txt
Enter contents to store till @
Developed for Beginners @
Written Successfully

#include< iostream>
#include< fstream>
using namespace std;
class Test {
 public:
 void read() {
  char c;
  char name[10];
  ifstream in;
  cout<<"Enter File Name: ";
  cin.getline(name,10);
  in.open(name,ios::in);
  if(!in){
   cout<<"File doesn't exists";
  }
  else {
   while(in.eof()==0) {
    in.get(c);
    cout<< c;
   }
  }
  in.close();
 }
};
int main() {
 Test t;
 t.read();
 return 0;
}
OUTPUT
Enter File Name: apps.txt
Developed for Beginners

#include< iostream>
#include< fstream>
using namespace std;
class Test {
 public:
 void copy() {
  char c;
  char f1[10],f2[10];
  ifstream in;
  ofstream out;
  cout<<"Enter File Name to Read: ";
  cin.getline(f1,10);
  cout<<"Enter File Name to Write: ";
  cin.getline(f2,10);
  in.open(f1,ios::in);
  out.open(f2,ios::out);
  if(!in){
   cout<<"File doesn't exists";
  }
  else {
   while(in.eof()==0) {
    in.get(c);
    out<< c;
   }
   cout<<"File Copied";
  }
  in.close();
  out.close();
 }
};
int main() {
 Test t;
 t.copy();
 return 0;
}
OUTPUT
Enter File Name to Read: apps.txt
Enter File Name to Write: alok.txt
File Copied.

#include< iostream>
#include< fstream>
using namespace std;
class Test {
 public:
 void rev() {
  char c;
  char name[10];
  ifstream in;
  cout<<"Enter File Name: ";
  cin.getline(name,10);
  in.open(name,ios::in);
  if(!in){
   cout<<"File doesn't exists";
  }
  else {
    in.seekg(0,ios::end);
   int size=in.tellg();

      for (int j=1; j<=size; j++){
          in.seekg(-j, ios::end);
          c=in.get();
          cout<< c;
         }
   }
 in.close();
 }
};
int main() {
 Test t;
 t.rev();
 return 0;
}
OUTPUT
Enter File Name: apps.txt
srennigeB rof depoleveD

#include< iostream>
#include< fstream>
using namespace std;
class Test {
 public:
 void mergee() {
  char c;
  char f1[20],f2[20],f3[20];
  ifstream in1,in2;
  ofstream out;
  cout<<"Enter 1st File Name: ";
  cin.getline(f1,20);
  cout<<"Enter 2nd File Name: ";
  cin.getline(f2,20);
  in1.open(f1,ios::in);
  in2.open(f2,ios::in);
  if(!in1 || !in2){
   cout<<"File doesn't exists";
   return;
  }
  else {
   cout<<"Enter 3rd File Name: ";
   cin.getline(f3,20);
   out.open(f3,ios::app);
   while(in1.eof()==0) {
    in1.get(c);
    out<< c;
   }
   while(in2.eof()==0){
    in2.get(c);
    out<< c;
   }
   out.close();
   cout<<"File Merged";
  }
  in1.close();
  in2.close();
 }
};
int main() {
 Test t;
 t.mergee();
 return 0;
}
OUTPUT
Enter 1st File Name: apps.txt
Enter 2nd File Name: sol.txt
Enter 3rd File Name: me.txt
File Merged


Get it on Google Play


CONTACT DETAILS

info@prowessapps.in
(8AM to 10PM):

+91-9026070669 , +91-9451396824

© 2016, prowessapps.in, All rights reserved