Advertisement
llsumitll

open multiple file form C++

Feb 13th, 2023
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.00 KB | Source Code | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <string>
  4. #include <sstream>
  5. #include <fstream>
  6.  
  7. using namespace std;
  8.  
  9. int main()
  10. {
  11.     vector <string> path { "/Users/sumit/Documents/projects/misc_c_cpp/RevisionCpp/RevisionCpp/grepprs_interrupt_1.log",
  12.         "/Users/sumit/Documents/projects/misc_c_cpp/RevisionCpp/RevisionCpp/grepprs_interrupt_2.log",
  13.         "/Users/sumit/Documents/projects/misc_c_cpp/RevisionCpp/RevisionCpp/grepprs_interrupt_3.log",
  14.         "/Users/sumit/Documents/projects/misc_c_cpp/RevisionCpp/RevisionCpp/grepprs_interrupt_4.log",};
  15.     string rline;
  16.    
  17.     for( string ps : path )
  18.     {
  19.         ifstream file(ps);
  20.         if(file.is_open())
  21.         {
  22.             cout << "file is open" << endl;
  23.             while( getline(file , rline))
  24.                 cout << "readline: " << rline << endl;
  25.             file.close();
  26.         }
  27.         else
  28.         {
  29.             cout << "error: fail to open file or file not found => path => " << ps << endl;
  30.         }
  31.     }
  32. }
  33.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement