Initial commit

This commit is contained in:
2022-04-28 04:34:45 +03:00
commit 4c0cdb2f71
30 changed files with 1218 additions and 0 deletions

6
cpp/Файлы/inp.txt Normal file
View File

@@ -0,0 +1,6 @@
554
1 4
2
3
4
5

48
cpp/Файлы/main.cpp Normal file
View File

@@ -0,0 +1,48 @@
#include <iostream>
#include <fstream>
using namespace std;
ifstream in_stream;
ofstream out_stream;
int main() {
in_stream.open("inp.txt");
out_stream.open("out.txt");
// Чтение файла
int N;
in_stream >> N;
cout << "Полученное число из файла: ";
cout << N << endl;
// Чтение двух чисел с одной строки:
int x;
in_stream >> x;
cout << "Первое число второй строки: " << x << endl;
int y;
in_stream >> y;
cout << "Второе число второй строки: " << y << endl;
// Чтение до конца файла:
int sum = 0;
int tmp;
while(!in_stream.eof()) {
in_stream >> tmp;
sum += tmp;
}
/* Аналог:
while (in_stream >> tmp) {
sum += tmp;
}
*/
cout << "Сумма оставшихся чисел в файле: " << sum << endl;
// Вывод в файл:
out_stream << sum << endl;
in_stream.close();
out_stream.close();
return 0;
}

1
cpp/Файлы/out.txt Normal file
View File

@@ -0,0 +1 @@
14