Counting number of words in a file using c++ : <p>I have been asked to develop program to count no. of lines and words in the file, this is my trial, my teacher said that I cant use >> operator for counting words and comparing but I could not handle it.</p>

<pre><code>    #include &lt;iostream&gt;
    #include &lt;fstream&gt;
    using namespace std;

    int numberLines = 0;
    int numberWords = 0;

    void numberOfLines(){

    cout&lt;&lt;"number of lines is " &lt;&lt; numberLines &lt;&lt; endl;
    }
    void numberWords(){
    cout &lt;&lt; "number of words is " &lt;&lt; numberWords &lt;&lt;endl;
    }

    int main(){
    string line;
    char a = '';
    ifstream myfile("files.txt");

    if(myfile.is_open()){
    while(!myfile.eof()){
        getline(myfile,line);
        cout&lt;&lt; line &lt;&lt; endl;
        numberLines++;
    }

    if ( a == ' '){
        NumberWords++;
    }

    }
    myfile.close();
    }
   numberOfLines();
   numberOfWords ();

   }
</code></pre>
