Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- #include <fstream>
- #include <string>
- //1-ФИО, 2-телефон, 3-должность, 4-IP-адрес
- struct item
- {
- string SNP;
- string tel;
- string position;
- string IP;
- };
- void show(item** arr) {
- int size = _msize(arr) / sizeof(arr[0]);
- for (int i = 0; i < size; i++) {
- cout << arr[i]->SNP << " "<<arr[i]->tel <<" "<< arr[i]->position<<" "<< arr[i]->IP<<endl;
- }
- }
- void add(item** &arr,string SNP,string tel,string position, string IP,bool file=1) {
- if (file == 0) {
- int size = _msize(arr) / sizeof(arr[0]);
- item** temp = new item * [size + 1];
- for (int i = 0; i < size; i++) {
- temp[i] = arr[i];
- }
- temp[size] = new item;
- temp[size]->SNP = SNP;
- temp[size]->tel = tel;
- temp[size]->position = position;
- temp[size]->IP = IP;
- swap(temp, arr);
- delete[]temp;
- }
- else if (file == 1) {
- ofstream out("E:\\hello.txt", std::ios::app);
- if (out.is_open())
- {
- out << SNP << " " << tel << " " << position << " " << IP << endl;
- }
- out.close();
- }
- }
- void read() {
- string line;
- ifstream in("E:\\hello.txt");
- if (in.is_open())
- {
- while (getline(in, line))
- {
- cout << line << std::endl;
- }
- }
- in.close(); // закрываем файл
- }
- void del(int N) {
- int counter = 0;
- string line,temp;
- ifstream in("E:\\hello.txt");
- if (in.is_open())
- {
- while (getline(in, line)) {
- cout << line;
- counter++;
- if (counter != N) {
- temp+=line;
- temp += "\n";
- cout <<endl<< temp;
- }
- }
- }
- in.close();
- cout << temp;// закрываем файл
- ofstream out;
- out.open("E:\\hello.txt",std::ios::out);
- if (out.is_open())
- {
- out << temp;
- }
- out.close();
- }
- void save(item** base) {
- ofstream out;
- out.open("E:\\hello.txt");
- if (out.is_open())
- {
- int size = _msize(base) / sizeof(base[0]);
- for (int i = 0; i < size; i++) {
- out << base[i]->SNP << " " << base[i]->tel << " " << base[i]->position << " " << base[i]->IP << endl;
- }
- }
- out.close();
- }
- int main()
- {
- item** base = new item * [0];
- add(base, "Anderson Thomas Petrovich", "8(928)1747295", "owner", "192.168.0.1");
- add(base, "Jobson Stanley Gurgenovich", "8(951)5182436", "worker", "192.168.0.254");
- add(base, "Romero John Doomovich", "8(951)5185465", "worker", "192.168.0.255");
- read();
- del(1);
- }
Add Comment
Please, Sign In to add comment