Tags: %TAGME{ tpaction="" web="SCMP118" tag="" }% view all tags

Strings, Vectors and Classes

Goal: Count the number if unique words in a series of lines.

1. Create a function to split a line of text into a vector of strings (words)

#include <iostream>
#include <sstream>
#include <string>

using namespace std;

int main()
    string s = "Somewhere down the road";
    istringstream iss(s);

        string subs;
        iss >> subs;
        cout << "Substring: " << subs << endl;
    } while (iss);

2. Create an object that stores words, and counts

class WordCount {
    string word;
    int count;
    WordCount ();
    WordCount(string W);
    WordCount(string W, int i);
    void Inc();
    int getCount();
    string getWord();

3. Make a vector of WordCount.

4. Count the words.

Edit | Attach | Watch | Print version | History: r3 < r2 < r1 | Backlinks | Raw View | Raw edit | More topic actions
Topic revision: r3 - 2018-04-10 - JimSkon
This site is powered by the TWiki collaboration platform Powered by PerlCopyright © 2008-2020 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback