Posted By

somada141 on 03/12/10


Tagged

function parameter stream Reference argument


Versions (?)

Pass a stream to a function #1


 / Published in: C++
 

  1. #include <fstream>
  2. #include <string>
  3. using namespace std;
  4.  
  5. method(ifstream &iFile){
  6. int c = 0;
  7. string line;
  8. while(!iFile.eof()) {
  9. getline (iFile, line);
  10. c++;
  11. }
  12. }
  13. int main(int argc, char**argv) {
  14. ifstream iFile;
  15. iFile.open(argv[1]);
  16. method(iFile);
  17. iFile.close();
  18. }

Report this snippet  

You need to login to post a comment.