Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 counting number of words using first_of() and first_not_of()
Index -> Programming, C++ -> C++ Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
a22asin




PostPosted: Mon Nov 03, 2014 6:05 pm   Post subject: counting number of words using first_of() and first_not_of()

Hi, im having trouble trying to count the number of word per line from a file using first_of() and first_not_of(). I am to assume that each word is separated by a space or a tab (\t). I have managed to get each line and count each line; but i have no idea how i would use the two codes to find and count each word per line. can u please help me by showing me how i would do it (im a visual learner). Thanks.

My Code so Far:

code:

#include <iostream>
#include <fstream>
#include <string>
using namespace std;

int main () {
        string line;
        int numLines = 0;
        ifstream file ("horton.txt");
        if (file.is_open()){
                while ( getline (file,line) ){
                        ++numLines;
                }
        file.close();
        cout <<numLines<<endl;
        }
        else cout << "Unable to open file";
}
Sponsor
Sponsor
Sponsor
sponsor
Display posts from previous:   
   Index -> Programming, C++ -> C++ Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 1 Posts ]
Jump to:   


Style:  
Search: