Advertisement
Guest User

main

a guest
Oct 16th, 2019
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.91 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <fstream>
  4. #include <cstdlib>
  5.  
  6. using std::string;
  7. using std::cerr;
  8. using std::endl;
  9. using std::cin;
  10. using std::cout;
  11. using std::ifstream;
  12.  
  13. const string inFileName = "in.txt";
  14. const string ERROR_NOT_NUMBER = "Error: must be integer!";
  15. const string ERROR_FILE_NOT_OPEN = "Error: File not open";
  16.  
  17. void sort(int array[], int nArray);
  18.  
  19. int main()
  20. {
  21. ifstream in;
  22.  
  23. try
  24. {
  25. in.open("in.txt");
  26. if (!in)
  27. throw inFileName + ERROR_FILE_NOT_OPEN;
  28.  
  29. int nArray = 0;
  30. in >> nArray;
  31. if (!in)
  32. throw inFileName + ERROR_NOT_NUMBER;
  33.  
  34. int *array = new int[nArray];
  35. for (int i = 0; i < nArray; ++i)
  36. {
  37. in >> array[i];
  38. if (!in)
  39. throw inFileName + ERROR_NOT_NUMBER;
  40. }
  41.  
  42. sort(array, nArray);
  43.  
  44. delete[] array;
  45. }
  46.  
  47. catch (const string & error)
  48. {
  49. cerr << endl << error << endl;
  50. return -1;
  51. }
  52.  
  53. in.close();
  54.  
  55. return 0;
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement