Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <string>
- #include <cstring>
- using namespace std;
- string str1 = "File_data.txt";
- void check_real_number();
- int main(int argc, char *argv[])
- {
- int index = 0;
- char *buffer = new char[1024];
- cout <<"Enter number, real number, and words by space:" << endl;
- cin.get(buffer[index]);
- while (buffer[index] != '\n')
- {
- ++index;
- cin.get(buffer[index]);
- }
- buffer[index] = '\0'; // нужен чтобы знать где заканчивается строка
- // запис даних у файл
- ofstream filename1;
- filename1.open(str1,std::ios_base::out | std::ios_base::trunc);
- filename1 << buffer;
- filename1.close();
- delete[] buffer;
- check_real_number();
- //sort_real_number();
- return 0;
- }
- void check_real_number() //Проверка или в файле есть действительные числаn
- {
- int n = 0;
- ifstream filename2;
- filename2.open(str1);
- if(!filename2.is_open())
- cerr << "Error, file is not open!" << endl;
- else
- {
- cout << "File is open!\n" << endl;
- string ch;
- while(!filename2.eof())
- {
- getline(filename2,ch);
- //cout << ch;
- }
- cout << endl;
- for (int i = 0; i < ch.length(); ++i)
- {
- if(ch[i] == '.' && int(ch[i-1]) >= '0' && int(ch[i+1] <= '9'))
- {
- if(ch[i] == '.' && ch[i+1] == '.')
- continue;
- ++n;
- }
- }
- cout << "There are real number: " << n <<endl;
- }
- cout << endl;
- filename2.close();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement