新聞中心
這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
在C++中獲取文件大小的方式有哪些-創(chuàng)新互聯(lián)
這篇文章給大家介紹在C++中獲取文件大小的方式有哪些,內(nèi)容非常詳細(xì),感興趣的小伙伴們可以參考借鑒,希望對大家能有所幫助。
C++獲取文件大小代碼示例:
#include < iostream> #include < io.h> #include < sys\stat.h> #include < afx.h> #define _AFXDLL using namespace std; void main() { // 此文件在工程打開狀態(tài)下為不可訪問 char* filepath = "..\\test.ncb"; // C++獲取文件大小方法一 struct _stat info; _stat(filepath, &info); int size = info.st_size; cout< < size< < endl; // C++獲取文件大小方法二 FILE* file = fopen(filepath, "rb"); if (file) { int size = filelength(fileno(file)); cout< < size< < endl; fclose(file); } // C++獲取文件大小方法三 CFile cfile; if (cfile.Open(filepath, CFile::modeRead)) { int size = cfile.GetLength(); cout< < size< < endl; } // C++獲取文件大小方法四 HANDLE handle = CreateFile(filepath, FILE_READ_EA, FILE_SHARE_READ, 0, OPEN_EXISTING, 0, 0); if (handle != INVALID_HANDLE_VALUE) { int size = GetFileSize(handle, NULL); cout< < size< < endl; CloseHandle(handle); } }
關(guān)于在C++中獲取文件大小的方式有哪些就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,可以學(xué)到更多知識。如果覺得文章不錯,可以把它分享出去讓更多的人看到。
網(wǎng)頁標(biāo)題:在C++中獲取文件大小的方式有哪些-創(chuàng)新互聯(lián)
路徑分享:http://fisionsoft.com.cn/article/ddheso.html