aboutsummaryrefslogtreecommitdiff
path: root/week07/Exercise2.cpp
blob: 2ec31d5ead4105c3d7e1b4ee5e7a16759f277134 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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();
}