Advertisement
Guest User

Untitled

a guest
Mar 24th, 2017
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.73 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <vector>
  4.  
  5. using namespace std;
  6.  
  7. void read_data(char *filename, int nword) {
  8.     ifstream input(filename);
  9.  
  10.     vector<string> temp(nword); //allocate a vector of size nword
  11.     unsigned int  freq; //to store frequency counter
  12.  
  13.     do {
  14.         //read in nword number of strings
  15.         for (int i = 0; i < nword; i++) {
  16.             input >> temp[i];
  17.         }
  18.  
  19.         //read in frequency
  20.         input >> freq;
  21.  
  22.         //TODO: do something with those vars
  23.         cout << freq << endl;
  24.  
  25.     } while (input.good());
  26.  
  27.     input.close();
  28. }
  29.  
  30. int main(int argc, char** argv) {
  31.     if (argc < 2) {
  32.         cerr << "missing file name" << endl;
  33.     }
  34.  
  35.     //read 2gram, notice we passed the number of words in the second param
  36.     read_data(argv[1], 2);
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement