Difference: Vector2CPP (2 vs. 3)

Revision 32018-04-10 - JimSkon

Line: 1 to 1
META TOPICPARENT name="Fall2017"

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)

<-- SyntaxHighlightingPlugin -->
#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);
<-- end SyntaxHighlightingPlugin -->

2. Create an object that stores words, and counts %CODE{"c++"}% class WordCount { private: string word; int count; public: WordCount (); WordCount(string W); WordCount(string W, int i);

void Inc();
  int getCount(); string getWord(); } %ENDCODE%

3. Make a vector of WordCount.

4. Count the words. \ No newline at end of file

This site is powered by the TWiki collaboration platform Powered by PerlCopyright © 2008-2019 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback