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

C#编程

开发平台:

Visual C++

  1. //=====================================
  2. // f1502.cpp
  3. // error proccess after error
  4. //=====================================
  5. #include<fstream>
  6. #include<iostream>
  7. using namespace std;
  8. //-------------------------------------
  9. void procFileName(string s);
  10. bool procOpenMode(string s);
  11. bool openIn(string s);
  12. bool openOut(string s);
  13. //-------------------------------------
  14. int main(){
  15.   procFileName("iabc");
  16.   procFileName("oabc");
  17. }//------------------------------------
  18. void procFileName(string s){
  19.   for(char c='0'; c<='9'; c++){
  20.     string t = s + c + ".txt";
  21.     if(!procOpenMode(t)){
  22.       cout<<"error opening "<<t<<"n";
  23.       return;
  24.     }
  25.   }
  26. }//------------------------------------
  27. bool procOpenMode(string s){
  28.   if(s[0]=='i' && openIn(s) || s[0]=='o' && openOut(s))
  29.     return true;
  30.   return false;
  31. }//------------------------------------
  32. bool openIn(string s){
  33.   ifstream in(s.c_str());
  34.   if(!in) return false;
  35.   for(string line; getline(in, line); cout<<line<<"n");
  36.   return true;
  37. }//------------------------------------
  38. bool openOut(string s){
  39.   fstream out(s.c_str(), ios::in|ios::out|ios::ate);
  40.   if(!out) return false;
  41.   cout<<s+" is here.n";
  42.   out<<s+" is ok.n";
  43.   return true;
  44. }//====================================
  45.