Website Summary Files Commits Branches @commit @diff @stats
path: root / Sem. 03 / getFileSize.cpp
blob: b9fa39e12c168f2928ecc00569baa79c5daa35b4 (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
25
26
27
28
29
30
#include <iostream>
#include <fstream>
#include <cstring>
using namespace std;

size_t getFileSize(std::ifstream& file)
{
	size_t currentPosition = file.tellg();

	file.seekg(0, ios::end);
	size_t result = file.tellg();
	file.seekg(currentPosition);
	return result;
}
int main()
{
	ifstream file("ddz.txt");
	
			
	if(!file.is_open())
	{
		std::cout << "Error while opening the file!" << std::endl;
		return -1;
	}
		
	
	std::cout << getFileSize(file) << " bytes" << std::endl;
	
	return 0;
}