Advertisement
Guest User

Untitled

a guest
Dec 3rd, 2016
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.83 KB | None | 0 0
  1. #define _CRT_SECURE_NO_DEPRECATE
  2. #include <iostream>
  3. #include <sstream>
  4. #include <fstream>
  5. #include <cmath>
  6. #include <stdio.h>
  7. #include <cstring>
  8. #include <iomanip>
  9. #include <string>
  10. #include <vector>
  11.  
  12.  
  13. using namespace std;
  14.  
  15. int main()
  16. {
  17. string selection;
  18.  
  19. do
  20. {
  21. //Main menu
  22. cout << "Count bytes in <file>" << endl;
  23. cout << "Count words in <file>" << endl;
  24. cout << "Copy <file> to <file>" << endl;
  25. cout << "Quit" << endl;
  26.  
  27. //Getting user input, converting to lowercase
  28. cout << "Please Enter A Selection From Above: ";
  29. getline(cin, selection);
  30.  
  31. for (int upper = 0; upper < selection.length(); upper++) {
  32. selection[upper] = tolower(selection[upper]);
  33. }
  34.  
  35. if (selection == "count bytes in \"input.txt\"")
  36. {
  37. //Counting bytes in file
  38. std::ifstream::pos_type filesize(const char* filename)
  39. {
  40. std::ifstream in(filename, std::ifstream::ate | std::ifstream::binary);
  41. in.seekg(0, in.end);
  42.  
  43. return in.tellg();
  44. }
  45. }
  46.  
  47. else if (selection == "count words in \"input.txt\"")
  48. {
  49. //Counting the words in the file
  50. ifstream input("input.txt");
  51. int words = 0;
  52. string word;
  53.  
  54. while (input >> word) {
  55. ++words;
  56. }
  57. cout << "There are this name words in the file: " << words << endl;
  58. }
  59.  
  60. else if (selection == "copy \"input.txt\" to \"output.txt\"")
  61. {
  62. //Copying input.txt to output.txt
  63. ifstream input("input.txt");
  64. ofstream output("output.txt");
  65. string stringy;
  66. getline(input, stringy);
  67. output << stringy << endl;
  68. input.close();
  69. output.close();
  70. cout << "Copying successful!" << endl;
  71. }
  72. // Quitting the program
  73. else if (selection == "quit")
  74. {
  75. cout << "Quitting..." << endl;
  76. }
  77. // Throwing errors
  78. else
  79. {
  80. cout << "Invalid input." << endl;
  81. }
  82. } while (selection != "quit");
  83.  
  84. return 0;
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement