aboutsummaryrefslogtreecommitdiff
path: root/week06/Exercise07.cpp
diff options
context:
space:
mode:
authorSyndamia <kamen@syndamia.com>2024-04-03 17:47:07 +0300
committerSyndamia <kamen@syndamia.com>2024-04-03 17:47:07 +0300
commit44d085f265583f0e3cbef294bbe2c8e300aaa452 (patch)
tree4899165f82a51beca1d4726db441a2749b628b9f /week06/Exercise07.cpp
parent6a8154ad7f2cbfbb2ae4f2ddda1cd0db0e430e44 (diff)
downloadoop-2023-solutions-44d085f265583f0e3cbef294bbe2c8e300aaa452.tar
oop-2023-solutions-44d085f265583f0e3cbef294bbe2c8e300aaa452.tar.gz
oop-2023-solutions-44d085f265583f0e3cbef294bbe2c8e300aaa452.zip
[w6] Added exercise descriptions and solutions to 1-9
Diffstat (limited to 'week06/Exercise07.cpp')
-rw-r--r--week06/Exercise07.cpp37
1 files changed, 37 insertions, 0 deletions
diff --git a/week06/Exercise07.cpp b/week06/Exercise07.cpp
new file mode 100644
index 0000000..2e07a0c
--- /dev/null
+++ b/week06/Exercise07.cpp
@@ -0,0 +1,37 @@
+#include <fstream>
+#include <iostream>
+
+int main() {
+ int m, n;
+ std::cin >> m >> n;
+
+ char fileName[1024];
+ std::cin.ignore();
+ std::cin.getline(fileName, 1024);
+
+ std::ifstream file(fileName);
+ if (!file.is_open()) {
+ std::cout << "Couldn't open file!" << std::endl;
+ return 1;
+ }
+
+ unsigned lineIndex = 1;
+ while (!file.eof()) {
+ if (file.peek() == '\n') {
+ lineIndex = 1;
+ file.get();
+ std::cout << std::endl;
+ continue;
+ }
+
+ if (m <= lineIndex && lineIndex <= n) {
+ std::cout << (char)file.peek();
+ }
+
+ lineIndex++;
+ file.get();
+ }
+ std::cout << std::endl;
+
+ file.close();
+}