如何用 C++ 獲取檔案的大小?
要獲取 C++ 中的檔案大小,首先開啟檔案並將其查詢至結尾。tell() 將告訴我們流的當前位置,該位置是檔案中的位元組數。
示例
#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";
}輸出
Size of the file is 44 bytes
廣告
資料結構
網路
關係資料庫管理系統
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP