C++ 从映射中的嵌套对引用值

C++ 从映射中的嵌套对引用值,c++,dictionary,vector,std-pair,C++,Dictionary,Vector,Std Pair,我有一个映射,它包含一个int和一对嵌套的两个字符串: map<int, pair<string, string> > books; 有人知道如何引用这对中的第一个字符串吗?显然,“it->second->first”不是解决方案 提前感谢。有两个错误it3->second不是迭代器。正如在注释中提到的,您正在将it2(迭代器)与字符串进行比较。有错误的行应如下所示: if(*it2 == (it3->second.first)) 地图也是很好的查找表。映射键对

我有一个映射,它包含一个int和一对嵌套的两个字符串:

map<int, pair<string, string> > books;
有人知道如何引用这对中的第一个字符串吗?显然,“it->second->first”不是解决方案


提前感谢。

有两个错误
it3->second
不是迭代器。正如在注释中提到的,您正在将it2(迭代器)与字符串进行比较。有错误的行应如下所示:

if(*it2 == (it3->second.first))

地图也是很好的查找表。映射键对应于由一对表示的两个值。下面的示例显示了如何访问键和对值

int main()
{
typedef map<string, pair<int, int> > op_type;
op_type op = {
             {"addu", make_pair(33, 1) }
             };

vector<string> this_line;

op_type::const_iterator i = op.find(this_line[0]);
if( i != op.end() )
{
    cout << "key: " << i-first << endl;
    cout << ".first value in pair " << i->second.first << endl;
    cout << ".second value in pair " << i->second.second << endl;
}
}
intmain()
{
typedef映射op_类型;
op_类型op={
{“addu”,使_对(33,1)}
};
这条线的向量;
op_type::const_迭代器i=op.find(此_行[0]);
如果(i!=op.end())
{

你不能把一个字符串和一个迭代器进行比较。但是迭代器不包含字符串吗?那么你认为一辆车里有人就等于一个人吗?不管怎样,迭代器不包含任何东西,它指向某个东西。是的,我现在明白了,谢谢。是的,我想建议添加一个指向it2的指针,但你已经做了他编辑。
//PUT BACK BORROWED BOOKS    
for (it2 = returned.begin(); it2 != returned.end(); it2++){ 
    //SEARCH FOR POSITION OF BOOK 
    for (it3 = books.begin(); it3 != books.end(); it3++){   
                    //PROBLEM IN LINE BELOW
        if(it2 == (it3->second-> first)) 
            int bookPos = it3 -> first;  


    }
}
if(*it2 == (it3->second.first))
int main()
{
typedef map<string, pair<int, int> > op_type;
op_type op = {
             {"addu", make_pair(33, 1) }
             };

vector<string> this_line;

op_type::const_iterator i = op.find(this_line[0]);
if( i != op.end() )
{
    cout << "key: " << i-first << endl;
    cout << ".first value in pair " << i->second.first << endl;
    cout << ".second value in pair " << i->second.second << endl;
}
}