Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- `#include <iostream>`
- #include <fstream>
- #include <string>
- #include <cstdlib>
- using namespace std;
- void show() // this function displays the file content
- {
- string file_nm, STRING;
- int i =0;
- cout<<"Please enter a file name: ";
- cin>>file_nm;
- ifstream infile;
- if (infile.good())
- {
- infile.open ("file_nm");
- while(!infile.eof()) // To get you all the lines.
- {
- getline(infile,STRING); // Saves the line in STRING.
- cout<<STRING; // Prints our STRING.
- }
- infile.close();
- }
- else
- {
- cout<< "Error opening the file: ";
- }
- i++;
- if (i%20==0)
- {
- system("pause");
- }
- }
- void add() // Appends to the end of the file
- {
- string txt, file_nm;
- cout<<"Enter a file name: ";
- cin>> file_nm;
- cout<<"Please enter a name to add to the file: ";
- cin>> txt;
- std::ofstream outfile;
- outfile.open(file_nm.c_str());
- outfile << file_nm;
- {
- outfile.close();
- }
- system("Pause");
- }
- int main(int argc, char *argv[])
- {
- //show();
- int cont = 1, choose;
- while(cont==1)
- {
- cout << "Main menun";
- cout <<"1) Show a listn";
- cout << "2) Add a namen";
- cout << "3) Exitn";
- cout<<" Please enter which option you want: "<<endl;
- cin >> choose;
- switch (choose)
- {
- case 1:
- show();
- break;
- case 2:
- add();
- break;
- case 3:
- cont=2;
- break;
- default:
- cout<<"BAD INPUT"<<endl;
- break;
- }
- }
- return EXIT_SUCCESS;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement