小玩文件

来源:互联网 发布:算法 专利 编辑:程序博客网 时间:2024/05/24 03:23
  1. #include <iostream>  
  2. #include <cstdlib>  
  3. #include <fstream>  
  4. using namespace std;  
  5. int main()  
  6. {  
  7.     fstream file;  
  8.     file.open("abc.txt",ios::in);  
  9.     if(!file)  
  10.     {  
  11.         cout<<"abc.txt can’t open."<<endl;  
  12.         exit(1);  
  13.     }  
  14.     char ch;  
  15.     int i=0;  
  16.     while(file.get(ch))  
  17.         ++i;  
  18.   
  19.     cout<<"Character: "<<i<<endl;  
  20.     file.close();  
  21.     return 0;  
  22. }  
0 0
原创粉丝点击