Initial commit
This commit is contained in:
6
cpp/Файлы/inp.txt
Normal file
6
cpp/Файлы/inp.txt
Normal file
@@ -0,0 +1,6 @@
|
||||
554
|
||||
1 4
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
48
cpp/Файлы/main.cpp
Normal file
48
cpp/Файлы/main.cpp
Normal 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
1
cpp/Файлы/out.txt
Normal file
@@ -0,0 +1 @@
|
||||
14
|
||||
Reference in New Issue
Block a user