Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _CRT_SECURE_NO_DEPRECATE
- #include <iostream>
- #include <sstream>
- #include <fstream>
- #include <cmath>
- #include <stdio.h>
- #include <cstring>
- #include <iomanip>
- #include <string>
- #include <vector>
- using namespace std;
- int main()
- {
- string selection;
- do
- {
- //Main menu
- cout << "Count bytes in <file>" << endl;
- cout << "Count words in <file>" << endl;
- cout << "Copy <file> to <file>" << endl;
- cout << "Quit" << endl;
- //Getting user input, converting to lowercase
- cout << "Please Enter A Selection From Above: ";
- getline(cin, selection);
- for (int upper = 0; upper < selection.length(); upper++) {
- selection[upper] = tolower(selection[upper]);
- }
- if (selection == "count bytes in \"input.txt\"")
- {
- //Counting bytes in file
- std::ifstream::pos_type filesize(const char* filename)
- {
- std::ifstream in(filename, std::ifstream::ate | std::ifstream::binary);
- in.seekg(0, in.end);
- return in.tellg();
- }
- }
- else if (selection == "count words in \"input.txt\"")
- {
- //Counting the words in the file
- ifstream input("input.txt");
- int words = 0;
- string word;
- while (input >> word) {
- ++words;
- }
- cout << "There are this name words in the file: " << words << endl;
- }
- else if (selection == "copy \"input.txt\" to \"output.txt\"")
- {
- //Copying input.txt to output.txt
- ifstream input("input.txt");
- ofstream output("output.txt");
- string stringy;
- getline(input, stringy);
- output << stringy << endl;
- input.close();
- output.close();
- cout << "Copying successful!" << endl;
- }
- // Quitting the program
- else if (selection == "quit")
- {
- cout << "Quitting..." << endl;
- }
- // Throwing errors
- else
- {
- cout << "Invalid input." << endl;
- }
- } while (selection != "quit");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement