Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<fstream>
- #include<iomanip>
- #include<Windows.h>
- #include<string>
- using namespace std;
- int main() {
- SetConsoleCP(1251);
- SetConsoleOutputCP(1251);
- string File;
- //Файл.txt
- ifstream fin;
- do {
- cout << "Введите имя файла: ";
- cin >> File;
- fin.open(File);
- } while (!fin);
- int count = 0, t;
- int chet = 0;
- while (!(fin >> ws).eof()) {
- streampos p;//объявление переменной p типа streampos
- p = fin.tellg();//получает указатель позиции файла
- fin.seekg(p);//устанавливает указатель позиции файла
- fin >> t;//запись в t файла
- fin.clear();//очитска состояния потока
- cout << t << " ";//вывод в консоль данных
- chet += 1;//счет элементов
- string str;
- fin.clear();//очистка потока
- if (!fin.fail()) {
- char c = fin.peek();//получения символа текущей позиции указателя
- if (c == ' ' || c == '\t' || c == '\n' || c == EOF) {
- count++;
- }
- else {
- fin.seekg(p);
- fin >> str;
- cout << "Найдена ошибка в элементах массива: " << "\"" << str << "\"" << endl;
- cout << "Номер индексa: " << "\"" << count + 1 << "\"" << endl;
- break;
- }
- }
- }
- cout << "Количество элементов в файле: " << chet << endl;
- int* mass = new(nothrow) int[chet];
- if (!mass) {
- cout << "Ошибка выделения памяти!" << endl;
- fin.close();
- return 0;
- }
- else if (chet == 0) {
- cout << "Файл пуст!" << endl;
- }
- else {
- cout << "Все круто!" << endl;
- }
- delete[]mass;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement