Soooooo..... my word recognition isn't right i think

This is a discussion on Soooooo..... my word recognition isn't right i think within the C++ Programming forums, part of the General Programming Boards category; I'm trying to get my program to count the occurences of vector in a file in the same directory as ...

  1. #1
    Registered User Jacob Cannon's Avatar
    Join Date
    Oct 2011
    Posts
    4

    Soooooo..... my word recognition isn't right i think

    I'm trying to get my program to count the occurences of vector in a file in the same directory as the program. Basic stuff, I just don't know how to get the for(int i = 0; word == "vector"; i++) right i think anyone got advice.

    Code:
    #include <iostream>
    #include <fstream>
    #include <vector>
    #include <string>
    
    
    using namespace std;
    
    
    int main()
    {
        vector<string> lookfor
        vector<string> words;
        ifstream in("occurence.txt");
        string word;
        int number = 0;
        while(in >> word)
            lookfor.push_back(word);
        for(int i = 0;word == "vector"; i++)
            number = number + 1;
        cout << endl << "The document has " << number << " occurences of the word 'vector'." << endl;
    }

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,505
    How about comparing with each word in your vector?

    As in
    if ( lookfor[i] == "vector" ) count++;
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Registered User Jacob Cannon's Avatar
    Join Date
    Oct 2011
    Posts
    4
    o bawls! thank you man! it worked like a charm, I'm really noob to C++. Reading out of thinking in C++ by Bruce Eckel and was needing help figuring out one of the examples.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 28
    Last Post: 10-23-2011, 07:17 PM
  2. Voice recognition SDK....
    By BobS0327 in forum C Programming
    Replies: 2
    Last Post: 03-31-2005, 08:50 AM
  3. object recognition
    By thedumbmutt in forum Tech Board
    Replies: 1
    Last Post: 04-02-2003, 06:00 AM
  4. speech recognition
    By mehmet in forum C++ Programming
    Replies: 4
    Last Post: 07-15-2002, 11:50 AM
  5. Microphone recognition...
    By weraw in forum C Programming
    Replies: 2
    Last Post: 12-26-2001, 10:11 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21