Monday, March 14, 2005

c tip : file size

pure C :
fseek(fp, 0, SEEK_END);
len = ftell(fp);

pure C++ :
差不多,用 iostream 的 seek 跟 tellg

unix :
struct stat fileInfo;
if (stat(filepath, &fileInfo) == -1)
handle error
len = fileInfo. st_size;

windows 1 :
hFile = CreateFile (...)
len =GetFileSize(hFile, NULL);

windows 2 :
跟 unix 一樣,只不過所有 posix function 以 _ (underline 開頭) ex _stat, _open

0 Comments:

Post a Comment

<< Home