Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <string>
- using namespace std;
- int getFileSize(const string &fileName); //Task 1
- void outputFile1(const string &fileName); //Task 2
- void outputFile2(const string &fileName);
- int main()
- {
- char exit = '\0'; // To exit program
- string fileName = "letters.txt";
- cout << "Task 1" << endl;
- cout << "There are " << getFileSize(fileName) << " byte(s) in the file " << fileName << endl;
- cout << endl << "Task 2" << endl;
- outputFile1(fileName);
- cout << "Task 3" << endl;
- outputFile2(fileName);
- cin >> exit;
- while (exit != '\0')
- return 0;
- }
- int getFileSize(const string & fileName)
- {
- fstream file(fileName, ios::in);
- int size = 0; //To store size
- file.seekg(0, ios::end);
- size = file.tellg();
- file.close();
- return size;
- }
- void outputFile1(const string &fileName)
- {
- char ch;
- string outName = "output1.txt"; //To name output file
- fstream inFile(fileName, ios::in);
- ofstream outFile(outName);
- cout << "Content of output1.txt: ";
- while (!inFile.eof())
- {
- inFile.get(ch);
- if (inFile.eof())
- break;
- cout << ch;
- outFile.put(ch);
- }
- inFile.close();
- cout << endl;
- return;
- }
- void outputFile2(const string & fileName)
- {
- char ch;
- string outName = "output2.txt"; //To name output file
- fstream inFile(fileName, ios::in);
- ofstream outFile(outName);
- cout << "Content of output2.txt: ";
- while (!inFile.eof())
- {
- int i = 0;
- inFile.seekg(1, ios::beg);
- inFile.get(ch);
- if (inFile.eof())
- break;
- cout << ch;
- outFile.put(ch);
- i++;
- }
- cout << endl;
- return;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement