
//
// This is example code from Chapter 4.6.3 "A text example" of
// "Programming -- Principles and Practice Using C++" by Bjarne Stroustrup
//

#include "std_lib_facilities.h"

void sort(vector<string>& w) {
	sort(w.begin(), w.end());
}
//------------------------------------------------------------------------------

bool isIn(vector<string> vs, string target) {
	for (string s : vs) if (s == target) return true;
	return false;
}

// simple dictionary: list of sorted words:
int main()
{
    vector<string> words; 
    string temp;
	vector<string> disliked{ "spear", "catapult", "fear", "leer" };
	cout << "Enter a bunch of words, \"quit\" to quit:\n";
	for (string temp; cin >> temp && temp != "quit"; )
		if (!isIn(disliked, temp)) words.push_back(temp);               // read whitespace separated words
      // put into vector

    cout << "Number of words: " << words.size() << endl;

	sort(words); // .begin(), words.end()); // sort "from beginning to end"

    for (int i = 0; i< words.size(); ++i) 
        if (i==0 || words[i-1]!=words[i]) // is this a new word?
            cout << words[i] << "\n";

	cout << "words.begin() == " << hex << &words[0] << endl;
}

//------------------------------------------------------------------------------
