Sinux1

PS6Q5

Mar 31st, 2016
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.42 KB | None | 0 0
  1. #include <fstream>
  2. #include <string>
  3. using namespace std;
  4.  
  5. int count_the_word(string filename, string word)
  6. {
  7.     int num_found = 0;
  8.     ifstream data_file;
  9.  
  10.     data_file.open(filename.c_str());
  11.  
  12.     while(!data_file.eof())
  13.     {
  14.         string data;
  15.         data_file >> data;
  16.  
  17.         if (data == word)
  18.         {
  19.             num_found++;
  20.         }
  21.     }
  22.     data_file.close();
  23.     return num_found;
  24.  
  25. }
Add Comment
Please, Sign In to add comment