我试图将双值< float,string >插入到map类中
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <set>
#include <iostream>
#include <map>
using namespace std;
int main()
{
map<float,string> output;
output.insert(pair<float,string> ( 200.5, "foo" ));
output.insert(pair<float,string> ( 100.5, "batr" ));
map<float,string>::iterator mps1;
map<float,string>::iterator mps2;
mps1 = output.begin();
mps2 = output.end();
while (mps1 != mps2)
{
cout<<mps2->first
<<" "
<<mps2->second; //crashes here
mps1++;
}
system("PAUSE");
}使用调试器,当它运行到以下行时,它会崩溃。
<<mps2->second;有人能给我解释一下吗,谢谢
发布于 2014-01-18 16:01:42
你应该访问的是mps1**,而不是** mps2**.**的
mps1是您要递增以供使用的迭代器;mps2是不可取消引用的“结束迭代器”。
这是一个相当基本的错误/逻辑错误。
https://stackoverflow.com/questions/21206419
复制相似问题