Tag:include c/c++ file operation
#include <iostream> #include <windows.h> #include <io.h> #include <sys\ Stat.h>using namespace std;void main () { char *filepath = "C:\\1.txt"; //method One 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); } //Method Two win32_find_data fileinfo; handle hfind; dword filesize; hfind = FindFirstFile (Filepath ,&fileinfo); if (Hfind != invalid_handle _value) fileSize = fileInfo.nFileSizeLow; cout<<filesize<<endl; findclose (HFind); //method Three file* file = fopen (filepath, "R"); if (file) { int size = filelength (Fileno (file)); cout<< Size<<endl; fclose (file); } //Method Four struct _stat info; _stat ( Filepath, &info); int size = info.st_size; cout<<size<< endl; return ;} Int nret = _findfirst (Str.c_str (), &FD);
How to get the file size in C + +