/* Lecture code 14.3
 *
 * Code to store and access elements of an STL set containing C strings.
 */
 
#include <iostream>
#include <cstring>
#include <string>
#include <set>
#include <sstream>
using namespace std;

/* Straight out of older lecture code. */
string GetLine()
{
	string line;
	getline(cin, line);
	return line;
}

/* Functor class that compares two C strings intelligently. */
struct CStringCompare
{
	bool operator() (const char* one, const char* two) const
	{
		return strcmp(one, two) < 0;
	}
};

int main()
{
	/* Use typedef to simplify things. */
	typedef set<const char*, CStringCompare> StringSet;
	
	StringSet mySet;
	mySet.insert("This is a string!");
	mySet.insert("So is this!");
	
	/* Print everything out. */
	for(StringSet::const_iterator itr = mySet.begin(); itr != mySet.end(); ++itr)
		cout << *itr << endl;
	
	/* Let the user query things. */
	while(true)
	{
		cout << "Enter query: ";
		const string line = GetLine();
		
		if(line.empty()) break;
		
		if(mySet.find(line.c_str()) != mySet.end())
			cout << "Yay!  Found it!" << endl;
		else
			cout << "Awww..." << endl;
	}
	return 0;
}