C + + Get file size

Source: Internet
Author: User

First, Introduction

I want to implement a simple Web server, encountered a problem is to get the file size sent to the client, namely: Content-length parameter.

Second, the method

Method One:

LongGetfilelength (stringstrpath) {    LongLsize =0; Ifstream Fin (Strpath.c_str (), iOS::inch|ios::binary); Charszbuf[1024x768* +] ="";  while(Fin.read (Szbuf,1024x768* +-1) ) {lsize+=strlen (SZBUF); memset (Szbuf,0,1024x768* +);    } fin.close (); Lsize+=strlen (SZBUF); returnlsize;}

Method Two:

Long Getfilelength (string  strpath) {        ifstream fin (Strpath.c_str (), iOS::in | iOS:: binary);    FIN.SEEKG (0, ios_base::end);     = Fin.tellg ();     long lsize = static_cast<long>(POS);    Fin.close ();     return lsize;}

C + + Get file 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.