

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
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
How can I get a file's 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
- Related Questions & Answers
- How can I get a file's permission mask using Python?
- How do I get a human-readable file size in bytes abbreviation using C#?
- How do I get into a Docker container's shell?
- How can I vary a shape's alpha with Tkinter?
- How do I get time of a Python program's execution?
- How can I format a float using matplotlib's LaTeX formatter?
- How do you get the file size in C#?
- How to set a widget's size in Tkinter?
- How can I get all element's immediate children with css selectors using selenium?
- How can I modify an existing column's data type?
- How to get full path of current file's directory in Python?
- How can we get the client's IP address in ASP.NET MVC C#?
- How can I pass arguments to Tkinter button's callback command?
- How can I match the start and end in Python's regex?
- How do I change a MongoDB user's password?
Advertisements