You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

31 lines
666 B
C++

A map of word opposites, using strings.
#include <iostream>
#include <map>
#include <string>
using namespace std;
int main()
{
map<string, string> mapObject;
int i;
mapObject.insert(pair<string, string>("yes", "no"));
mapObject.insert(pair<string, string>("up", "down"));
mapObject.insert(pair<string, string>("left", "right"));
mapObject.insert(pair<string, string>("good", "bad"));
string s;
cout << "Enter word: ";
cin >> s;
map<string, string>::iterator p;
p = mapObject.find(s);
if(p != mapObject.end())
cout << "Opposite: " << p->second;
else
cout << "Word not in map.\n";
return 0;
}