您好,欢迎来到[编程问答]网站首页   源码下载   电子书籍   软件下载   专题
当前位置:首页 >> 编程问答 >> VC/MFC >> map中find方法的问题

map中find方法的问题

来源:网络整理     时间:2016/8/31 1:34:28     关键词:

关于网友提出的“ map中find方法的问题”问题疑问,本网通过在网上对“ map中find方法的问题”有关的相关答案进行了整理,供用户进行参考,详细问题解答如下:

问题: map中find方法的问题
描述:

使用map中的find()方法  VC6中
编译提示出错:
--------------------Configuration: AutoParticiple - Win32 Debug--------------------
Compiling...
Dictionary.cpp
F:\Project\Visual C++\AutoParticiple\Dictionary.cpp(30) : error C2679: binary '=' : no operator defined which takes a right-hand operand of type 'class std::_Tree<>,struct std::map<>,cla
ss std::allocator >::_Kfn,struct std::less,class std::allocator >::const_iterator' (or there is no acceptable conversion)
F:\Project\Visual C++\AutoParticiple\Dictionary.cpp(31) : error C2679: binary '!=' : no operator defined which takes a right-hand operand of type 'class std::_Tree<>,struct std::map<>,cl
ass std::allocator >::_Kfn,struct std::less,class std::allocator >::const_iterator' (or there is no acceptable conversion)
Error executing cl.exe.
AutoParticiple.exe - 2 error(s), 0 warning(s)
源码如下
Dictionary.h
#ifndef _Dictionary_H_
#define _Dictionary_H_
#pragma warning(disable: 4786)
#include 
#include 
#include 
#include 
using namespace std; 
const string DICTIONARYNAME("words.dictionary");
class Dictionary {
public:
Dictionary(); 
~Dictionary(); 
bool IsWord(string&) const; 
int getIndex(string&) const;
int getFrequency(int) const;
private:
map wordDictionary;
map frequencyDictionary;
void OpenDictionary();
};
#endif
Dictioanry.cpp
#include "Dictionary.h"
Dictionary::Dictionary() 
{
OpenDictionary();
}
Dictionary::~Dictionary() 
{
wordDictionary.clear();
frequencyDictionary.clear();
}
/* Esitimate whether a word in word dictionary. */
bool Dictionary::IsWord(string& word) const
{
if(wordDictionary.find(word) != wordDictionary.end())
return true;
return false;
}
int Dictionary::getFrequency(int id) const
{
map::iterator position;
position =  frequencyDictionary.find(id);
if(position != frequencyDictionary.end())
return (*position).second;
else
return -1;
}
void Dictionary::OpenDictionary()
{
FILE *fpDictionary;
if((fpDictionary = fopen(DICTIONARYNAME.c_str(), "r")) == NULL) {
cout << "Cannot open the Dictionary file!";
exit(1);
}
int id, frequency;
char word[16];
while(fscanf(fpDictionary, "%d %s %d", &id, word, &frequency) != EOF) {
wordDictionary.insert(pair(word, id));
frequencyDictionary.insert(pair(id, frequency));
}
fclose(fpDictionary);
}
如何解决?


以上介绍了“ map中find方法的问题”的问题解答,希望对有需要的网友有所帮助。
本文网址链接:http://www.codes51.com/itwd/3672762.html

相关图片

相关文章