Home > Article > Backend Development > How to Get a File's Size in C : A Simple and Reliable Approach?
Determining File Size in C
The query "How can I obtain a file's size in C ?" prompts exploration into the most prevalent method for accomplishing this task while adhering to specific criteria.
Criteria:
Common Approach:
Utilizing C 's native file I/O features, a common approach to determine the size of a file involves the following steps:
#include <fstream> std::ifstream::pos_type filesize(const char* filename) { std::ifstream in(filename, std::ifstream::ate | std::ifstream::binary); return in.tellg(); }
Explanation:
Additional Information:
Please note that this solution assumes the file is not open in other applications, which may affect the file size. For further details on file handling in C , refer to: http://www.cplusplus.com/doc/tutorial/files/.
The above is the detailed content of How to Get a File's Size in C : A Simple and Reliable Approach?. For more information, please follow other related articles on the PHP Chinese website!