Advertisement
Guest User

Untitled

a guest
Nov 28th, 2014
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.19 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include "conio.h"
  4. #include <string>
  5.  
  6. using namespace std;
  7. int main()
  8. {
  9.  
  10.         // TASK 1
  11.         ifstream fs("file1.txt");
  12.  
  13.         ofstream fs2;
  14.         fs2.open("file2.txt");
  15.  
  16.         fstream fs3("file3.txt", fstream::in | fstream::out);
  17.  
  18.  
  19.         // TASK 2
  20.         if (!fs.good())
  21.                 cerr << "File1 not found !" << endl;
  22.  
  23.         if (fs2.fail())
  24.                 cerr << "File2 not found !" << endl;
  25.  
  26.         if (fs3.fail())
  27.                 cerr << "File3 not found !" << endl;
  28.  
  29.         fs2.close(); // only file2.txt opened
  30.  
  31.  
  32.         // TASK 3
  33.         fs.open("file2.txt");
  34.         fs2.open("file2.txt");
  35.         fs3.open("file2.txt");
  36.  
  37.        
  38.         // TASK 4
  39.         string inText;
  40.         cout << "Enter text you want to save in file :\n";
  41.         getline (cin, inText);
  42.         fs2 << "This magic program saved text you entered! It is as following:\n" << inText << "\n";
  43.  
  44.  
  45.         // TASK 5
  46.         char c = 0;
  47.         while (!fs3.eof()) // cout file
  48.         {
  49.                 fs3.get(c);
  50.                 cout << c;
  51.         }
  52.  
  53.  
  54.         fs.close();
  55.         fs2.close();
  56.         fs3.close();
  57.  
  58.         _getch();
  59.         return 0;
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement