ftell//fopen//fseek//test ok

fopen的使用

如果myfile.txt文件的权限是111, 文件也是可以打开的 

#include 

int main ()
{
  FILE * pFile;
  long size;
  //如果myfile.txt文件的权限是111, 文件也是可以打开的
  pFile = fopen ("myfile.txt","rb");
  if (pFile==NULL) 
  {
   perror ("Error opening file");
  }
  else
  {
    fseek (pFile, 0, SEEK_END);   // non-portable
    size=ftell (pFile);
    fclose (pFile);
    printf ("Size of myfile.txt: %ld bytes.\n",size);
  }
  return 0;
}

userdeMacBook-Air:test userfei$ touch ftell.cpp
userdeMacBook-Air:test userfei$ vi ftell.cpp 
userdeMacBook-Air:test userfei$ g++ ftell.cpp 
userdeMacBook-Air:test userfei$ touch myfile.txt
userdeMacBook-Air:test userfei$ echo "11111111111"> myfile.txt 
userdeMacBook-Air:test userfei$ cat myfile.txt 
11111111111
userdeMacBook-Air:test userfei$ ./a.out
Size of myfile.txt: 12 bytes.
userdeMacBook-Air:test userfei$ 
 

你可能感兴趣的:(c++,服务器,linux,前端)