C + + Get file size

Source: Internet
Author: User
  #include  < iostream>  #include  < io.h>  #include  <  sys\stat.h>  #include  < afx.h>  #define  _afxdll   Using namespace  std;   Void main ()   { //  This file is not accessible   char* filepath =  in the project's open state. \\TEST.NCB ";  // c++ Get file size method one   struct _stat info;   _stat (Filepath, &info);   int size = info.st_size;   cout< < size< < endl;  // c++ Get File size method two   File* file = fopen (filepath,  "RB");   if  (file)   {  Int size = filelength (Fileno (file));   cout< <  size< < endl;   fclose (file);  }  // c++ get file size method three   cfile cfile;   if  (CFile. Open (Filepath, cfile::moderead))   {  Int size = cfile. GEtlength ();   cout< < size< < endl;  }  // c++ get file size method four   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); C + + Get file size method Five, this method does not need to open the file can get directly to the file size CFile CFile;
CFileStatus Rstatus;
CFile::GetStatus (_t ("D:\\Program files\\360\\360sd\\360hips.exe"), rstatus);
ULONGLONG ulong = rstatus.m_size;

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.