diff options
Diffstat (limited to 'week07/Exercise2.cpp')
| -rw-r--r-- | week07/Exercise2.cpp | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/week07/Exercise2.cpp b/week07/Exercise2.cpp new file mode 100644 index 0000000..2ec31d5 --- /dev/null +++ b/week07/Exercise2.cpp @@ -0,0 +1,24 @@ +#include <fstream> +#include <iostream> + +int main() { + char fileName[1024]; + std::cin.getline(fileName, 1024); + + std::ifstream file(fileName); + if (!file.is_open()) { + std::cout << "Couldn't open file!" << std::endl; + return -1; + } + + file.seekg(0, std::ios::end); + int third = file.tellg() / 3; + file.seekg(2 * third - 1, std::ios::beg); + + while (third <= file.tellg()) { + std::cout << (char)file.peek(); + file.seekg(-1, std::ios::cur); + } + + file.close(); +} |
