ch21_1.cpp
资源名称:c.rar [点击查看]
上传用户:puke2000
上传日期:2022-07-25
资源大小:912k
文件大小:1k
源码类别:

C#编程

开发平台:

Visual C++

  1. //**********************
  2. //**    ch21_1.cpp    **
  3. //**********************
  4. #include <fstream.h>
  5. #include <iostream.h>
  6. #include <stdlib.h>
  7. void main(int argc, char ** argv)
  8. {
  9.   ifstream source(argv[1]);      //打开文件
  10.   char line[128];
  11.   try{
  12.     if(source.fail())
  13.       throw argv[1];
  14.   }
  15.   catch(char* s)
  16.   {
  17.     cout <<"error opening the file "<<s <<endl;     exit(1);
  18.   }
  19.   while(!source.eof()){
  20.     source.getline(line, sizeof(line));
  21.     cout <<line <<endl;
  22.   }
  23.   source.close();
  24. }