force1987

19/04

Apr 19th, 2021 (edited)
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.33 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3. #include <fstream>
  4. #include <string>
  5. //1-ФИО, 2-телефон, 3-должность, 4-IP-адрес
  6.  
  7. struct item
  8. {
  9. string SNP;
  10. string tel;
  11. string position;
  12. string IP;
  13. };
  14.  
  15. void show(item** arr) {
  16. int size = _msize(arr) / sizeof(arr[0]);
  17. for (int i = 0; i < size; i++) {
  18. cout << arr[i]->SNP << " "<<arr[i]->tel <<" "<< arr[i]->position<<" "<< arr[i]->IP<<endl;
  19. }
  20. }
  21.  
  22. void add(item** &arr,string SNP,string tel,string position, string IP,bool file=1) {
  23. if (file == 0) {
  24. int size = _msize(arr) / sizeof(arr[0]);
  25. item** temp = new item * [size + 1];
  26. for (int i = 0; i < size; i++) {
  27. temp[i] = arr[i];
  28. }
  29. temp[size] = new item;
  30. temp[size]->SNP = SNP;
  31. temp[size]->tel = tel;
  32. temp[size]->position = position;
  33. temp[size]->IP = IP;
  34. swap(temp, arr);
  35. delete[]temp;
  36. }
  37. else if (file == 1) {
  38. ofstream out("E:\\hello.txt", std::ios::app);
  39. if (out.is_open())
  40. {
  41. out << SNP << " " << tel << " " << position << " " << IP << endl;
  42. }
  43. out.close();
  44. }
  45. }
  46.  
  47. void read() {
  48. string line;
  49. ifstream in("E:\\hello.txt");
  50. if (in.is_open())
  51. {
  52. while (getline(in, line))
  53. {
  54. cout << line << std::endl;
  55. }
  56. }
  57. in.close(); // закрываем файл
  58. }
  59.  
  60. void del(int N) {
  61. int counter = 0;
  62. string line,temp;
  63. ifstream in("E:\\hello.txt");
  64. if (in.is_open())
  65. {
  66. while (getline(in, line)) {
  67. cout << line;
  68. counter++;
  69. if (counter != N) {
  70. temp+=line;
  71. temp += "\n";
  72. cout <<endl<< temp;
  73. }
  74. }
  75. }
  76. in.close();
  77. cout << temp;// закрываем файл
  78.  
  79. ofstream out;
  80. out.open("E:\\hello.txt",std::ios::out);
  81. if (out.is_open())
  82. {
  83. out << temp;
  84. }
  85. out.close();
  86. }
  87.  
  88. void save(item** base) {
  89. ofstream out;
  90. out.open("E:\\hello.txt");
  91. if (out.is_open())
  92. {
  93. int size = _msize(base) / sizeof(base[0]);
  94. for (int i = 0; i < size; i++) {
  95. out << base[i]->SNP << " " << base[i]->tel << " " << base[i]->position << " " << base[i]->IP << endl;
  96. }
  97. }
  98. out.close();
  99. }
  100.  
  101. int main()
  102. {
  103. item** base = new item * [0];
  104. add(base, "Anderson Thomas Petrovich", "8(928)1747295", "owner", "192.168.0.1");
  105. add(base, "Jobson Stanley Gurgenovich", "8(951)5182436", "worker", "192.168.0.254");
  106. add(base, "Romero John Doomovich", "8(951)5185465", "worker", "192.168.0.255");
  107. read();
  108. del(1);
  109. }
Add Comment
Please, Sign In to add comment