// File; iss_demo.cpp // Demonstrate using istringstream to parse text #include #include #include #include using namespace std; int main() { map Tab; ifstream inf("items.txt"); string category,itemName; // Store the data in the table getline(inf, category); while (!inf.eof()) { getline(inf,itemName); while (!inf.eof() && itemName.size()>0) { Tab.insert(pair(itemName,category)); getline(inf, itemName); } if (!inf.eof()) getline(inf, category); } // Do lookups string key; map::iterator it; cout << "Enter item to look for. Hit return to quit >"; getline(cin,key); while (key.size()>0) { if ((it=Tab.find(key))!=Tab.end()) cout << "Found value " << it->second << endl; else cout << "Did not find " << key << " in the lookup table\n"; cout << "Enter item to look for. Hit return to quit >"; getline(cin,key); } }