Advertisement
Guest User

Untitled

a guest
Feb 26th, 2020
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.34 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <string>
  4. #include <iomanip>
  5. #include <Windows.h>
  6.  
  7. using namespace std;
  8.  
  9. int main()
  10. {
  11. SetConsoleCP(1251);
  12. SetConsoleOutputCP(1251);
  13. char c;
  14. int i = 0, t, pos;
  15. ifstream f;
  16. string n,s;
  17. bool mistake = false;
  18. do {
  19. cout << "Введите название файла ";
  20. cin >> n;
  21. f.open(n);
  22. if (f.good())
  23. break;
  24. else cout << "Файл с названием \"" << n << "\" не найден" << endl;
  25.  
  26. } while (true);
  27.  
  28. f.peek();
  29. while (!f.eof())
  30. {
  31. f >> ws;
  32. pos = f.tellg();
  33. f >> ws;
  34. f >> t;
  35. c = f.peek();
  36. if (f.fail() || (c != ' ') && (c != '\t') && (c != '\n') && (c != EOF))
  37. {
  38. f.clear();
  39. mistake = true;
  40. break;
  41. }
  42. i++;
  43. }
  44.  
  45. if (!i)
  46. {
  47. cout << "Файл пуст" << endl;
  48. return 0;
  49. }
  50.  
  51. if (mistake)
  52. {
  53. f.clear();
  54. f.seekg(pos);
  55. f >> s;
  56. cout << "В элементе \"" << s << "\", обнаружена ошибка \nПорядковый номер элемента = " << i << "\nПозиция указателя = " << pos + 1 << endl;
  57. }
  58. int j = 0,*arr=NULL;
  59. try
  60. {
  61. arr = new int[i];
  62. }
  63. catch (bad_alloc) {}
  64. if (!arr)
  65. {
  66. cout << "память не была выделенна" << endl;
  67. }
  68. while (!f.eof())
  69. {
  70. f >> arr[j];
  71. cout << arr[j];
  72. j++;
  73.  
  74. }
  75.  
  76.  
  77.  
  78.  
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement