Website Summary Files Commits Branches @commit @diff @stats
path: root / Sem. 03
diff options
context:
space:
mode:
1 files changed, 26 insertions, 0 deletions
-rw-r--r--Sem. 03/text_file_length.cpp26
diff --git a/Sem. 03/text_file_length.cpp b/Sem. 03/text_file_length.cpp
new file mode 100644
index 0000000..c2d09b7
--- /dev/null
+++ b/Sem. 03/text_file_length.cpp
@@ -0,0 +1,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");
+}