Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <fstream>
- #include <cstdlib>
- using std::string;
- using std::cerr;
- using std::endl;
- using std::cin;
- using std::cout;
- using std::ifstream;
- const string inFileName = "in.txt";
- const string ERROR_NOT_NUMBER = "Error: must be integer!";
- const string ERROR_FILE_NOT_OPEN = "Error: File not open";
- void sort(int array[], int nArray);
- int main()
- {
- ifstream in;
- try
- {
- in.open("in.txt");
- if (!in)
- throw inFileName + ERROR_FILE_NOT_OPEN;
- int nArray = 0;
- in >> nArray;
- if (!in)
- throw inFileName + ERROR_NOT_NUMBER;
- int *array = new int[nArray];
- for (int i = 0; i < nArray; ++i)
- {
- in >> array[i];
- if (!in)
- throw inFileName + ERROR_NOT_NUMBER;
- }
- sort(array, nArray);
- delete[] array;
- }
- catch (const string & error)
- {
- cerr << endl << error << endl;
- return -1;
- }
- in.close();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement