
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Get File Size in C++
To get a file’s size in C++ first open the file and seek it to the end. tell() will tell us the current position of the stream, which will be the number of bytes in the file.
Example
#include<iostream> #include<fstream> using namespace std; int main() { ifstream in_file("a.txt", ios::binary); in_file.seekg(0, ios::end); int file_size = in_file.tellg(); cout<<"Size of the file is"<<" "<< file_size<<" "<<"bytes"; }
Output
Size of the file is 44 bytes
Advertisements