Converting call from a .txt into a string c++ -


i'm trying read text file , count number of occurences of each word , export results different text file. i'm allowed use loops , arrays assignment. i'm looking slight push in right direction, in beginning of code. it's not compiling correctly!

using namespace std; #include <iostream> #include <iomanip> #include <string> #include <fstream>   void put(string word, string words[], int counts[], int & size)  {  int w;  (w = 0; w < size && word >= words[w]; w++);  if (w >= size) {  words[w] = word;  counts[w] = 1;  ++size; } else if (word < words[w]) {  (int = size - 1; >= w; i--) {  words[i + 1] = words[i];  counts[i + 1] = counts[i]; } words[w] = word; counts[w] = 1; ++size; } else { counts[w] = counts[w] + 1; } }  int main() {  int word;   ifstream input("input.txt");  ofstream chout("charcount.txt");  ofstream wout("wordscounts.txt");    int inputsize = sizeof(input) / sizeof(string);  int counts[100];  const int max = 100;  string words[max];  int wordssize = 0;    while (input >> word) {   put(input[word], words, counts, wordssize);  }     wout << "       word  frequency" << endl;  (word = 0; word < inputsize; ++word) {  wout << setw(10) << words[word] << setw(4) << counts[word] << endl;  }     chout.close(); wout.close();  system("pause"); return 0; } 

this line:

put(input[word], words, counts, wordssize); 

you trying index ifstream. not allowed. compiler (g++ 4.8.4) said:

no match ‘operator[]’ (operand types ‘std::ifstream {aka std::basic_ifstream<char>}’ , ‘int’) 

Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -