Website Summary Files Commits Branches @commit @diff @stats
path: root / Sem. 03 / text_file_length.cpp
blob: c2d09b72c6a1eb2cfa12172db7e56bc324b7d4c9 (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
#include <iostream>
#include <fstream>
#pragma warning(disable:4996)
using namespace std;

const size_t capacity = 1024;

size_t getTextFileLength(const char* fileName)
{
	ifstream file(fileName);
	if (!file.is_open())
		return 0;

	size_t count = 0; 
	while (!file.eof()) // there are better ways  to do that
	{
		file.get();
		count++;
	}

	return count - 1;
}
int main()
{	
	std::cout << getTextFileLength("test.txt");
}