Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "pch.h"
- #include <iostream>
- #include <fstream>
- #include <string>
- using namespace std;
- /*
- This is just a function implementation of a
- section of project.
- need to read a file ( attached ) , update
- the amount of the specified client given the client id in the file. Then write back to the file */
- class editor {
- private:
- fstream fs;
- ofstream ofs_1;
- public:
- editor()
- {
- fs.open("users.txt", ios::ios_base::in || ios::ios_base::out);
- ofs_1.open("users1.txt", ios::ios_base::app);
- unsigned int stat_cap, id, acc_no;
- string fname, lname;
- if (ofs_1.is_open())
- {
- if (fs.is_open())
- {
- while (fs >> id >> fname >> lname >> acc_no >> stat_cap)
- {
- if (id == get_id())
- {
- std::cout << id << " " << fname + " " + lname << " " << acc_no << " " << stat_cap << std::endl;
- std::cout << "editing ..." << std::endl;
- edit(std::ref(stat_cap));
- ofs_1 << id << fname + " " + lname << " " << acc_no << " " << stat_cap << std::endl;
- }
- ofs_1 << id << fname + " " + lname << " " << acc_no << " " << stat_cap << std::endl;
- }
- }
- else
- {
- perror("Read file could not open");
- }
- }
- else
- {
- perror("Write file could not open");
- }
- }
- unsigned int get_id()
- {
- unsigned int passed_id;
- std::cout << " Enter your id : ";
- cin >> passed_id;
- return passed_id;
- }
- unsigned int edit(unsigned int &stat_cap)
- {
- unsigned int *ptr = NULL;
- ptr = &stat_cap;
- stat_cap = *ptr + 10000;
- return stat_cap;
- }
- };
- int main()
- {
- int status;
- editor edit_it;
- status = remove("users.txt");
- if (status == 0)
- {
- std::cout << " Original file deleted successfully" << std::endl;
- }
- else
- {
- std::cout << " Error ! original file could not be deleted " << std::endl;
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment