From 7c5a4a8a35e27e341e11229a210909a008fe13f5 Mon Sep 17 00:00:00 2001 From: oltnd Date: Tue, 5 Nov 2024 11:33:23 +0300 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8=D1=82?= =?UTF-8?q?=D1=8C=20z4.cpp?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- z4.cpp | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 z4.cpp diff --git a/z4.cpp b/z4.cpp new file mode 100644 index 0000000..da51966 --- /dev/null +++ b/z4.cpp @@ -0,0 +1,42 @@ +#include +#include +#include +#include +using namespace std; +int main() { + string input; + cout << "Введите строку: "; + getline(cin, input); + + // Запись строки в файл + ofstream outFile("output.txt"); + if (outFile.is_open()) { + outFile << input; + outFile.close(); + } else { + cerr << "Ошибка открытия файла для записи." << endl; + return 1; + } + + // Чтение из файла + ifstream inFile("output.txt"); + if (!inFile.is_open()) { + cerr << "Ошибка открытия файла для чтения." << endl; + return 1; + } + + string fileContent; + getline(inFile, fileContent); + inFile.close(); + + // Извлечение и вывод только цифр + string digitsOnly; + for (char ch : fileContent) { + if (isdigit(ch)) { + digitsOnly += ch; + } + } + + cout << "Цифры из файла: " << digitsOnly << endl; + return 0; +}