I'm having a problem with my multimap. I've looked on the internet, and I can't see anything different to what other people have done. I get one of those long and unhelpful errors. I know it's against the policy to post uni questions on here, but our C++ lecturer has gone to Italy and China for 4 weeks and the other guy isn't so familiar in C++. Could anyone help me out please ?
Code:
#include <iostream>
#include <fstream>
#include <string>
#include <map>
#include <cstdlib>
using namespace std;
void readFile(multimap<string, string>& words);
int main()
{
typedef multimap<string, string>::const_iterator mConstItr;
multimap<string, string> words;
string searchWord;
string originalWord;
pair<mConstItr, mConstItr> rangeOfKey;
readFile(words);
cout << "What word would you like to see anagrams of, if they exist ? ";
cin >> searchWord;
while(!cin.eof())
{
originalWord = searchWord;
sort(searchWord.begin(), searchWord.end());
rangeOfKey = words.equal_range(searchWord);
if (rangeOfKey.first != 0)
{
for (mConstItr index = rangeOfKey.first; index != rangeOfKey.second; index++)
{
if (index->second != originalWord)
cout << index->second << endl;
}
}
else
{
cout << "No anagrams found." << endl;
}
cout << endl << "What is the next word to see anagrams of ? ";
cin >> searchWord;
}
return 0;
}
void readFile(multimap<string, string>& words)
{
char dictFile[20];
string tempWord;
ifstream inData;
int wordCounter = 0;
pair<string, string> row;
cout << "What is the name of the dictionary file ? ";
cin >> dictFile;
inData.open(dictFile);
if (!inData.good())
{
cerr << "Data file not found or corrupted";
exit(1);
}
inData >> tempWord;
while (!inData.eof())
{
wordCounter++;
row.second = tempWord;
sort(tempWord.begin(), tempWord.end());
row.first = tempWord;
words.insert(row);
inData >> tempWord;
}
inData.close();
cout << wordCounter << " words read in from file." << endl;
}