c++使用map的时候出现了这个,请问是什么问题?
附一下我的代码:
#include<iostream>
#include<time.h>
#include<string>
#include<map>
using namespace std;
#define random(x) rand()%(x)
int main()
{
srand(time(NULL));
multimap<int, int>insstream;
int count = 0;
while (count < 320) {
int m = random(319);
count++;
insstream.insert(pair<int, int>(count,m+1));
int m1 = random(m + 1);
count++;
insstream.insert(pair<int, int>(count, m1));
count++;
insstream.insert(pair<int, int>(count, m1+1));
int m2 = random(319 - (m1 + 2) + 1) + m1 + 2;
count++;
insstream.insert(pair<int, int>(count, m2));
}
//检测指令流
//for (auto ins = insstream.begin(); ins != insstream.end(); ins++)
//cout << ins->second << " ";
multimap<int, int>pagestream;
for (auto ins = insstream.begin(); ins != insstream.end(); ins++)
pagestream.insert(pair<int, int>(ins->first, ins->second/10));
//检测页面流
for (auto page = pagestream.begin(); page != pagestream.end(); page++)
cout << page->second << " ";
cout << endl;
string choose;
cout << "*************************************************" << endl;
cout << "欢迎使用本程序~" << endl;
cout << "请选择您需要的算法(FIFO、LRU、OPT、LFR、CLOCK):" << endl;
cin >> choose;
int allocation = random(6 - 3 + 1) + 3;
cout << "本次分配的物理块数为:" << allocation << "块!" << endl;
map<int, int>run;
if (choose == "FIFO" || choose == "fifo") {
run.insert(pair<int, int>(pagestream.find(1)->first, pagestream.find(1)->second));
for (auto page = pagestream.begin(); page != pagestream.end(); page++)
{
for (auto r = run.begin(); r != run.end() && r->second != page->second; r++)
{
if (r == run.find(run.size())) {
if (run.size() < allocation) {
run.insert(pair<int, int>(page->first, page->second));
}
else if (run.size() == allocation) {
run.erase(run.find(1));
run.insert(pair<int, int>(page->first, page->second));
}
}
}
for (auto r = run.begin(); r != run.end(); r++)
cout << r->second << " ";
cout << endl;
}
}
else if (choose == "LRU"|| choose == "lru") {
}
else if (choose == "OPT"|| choose == "opt") {
}
else if (choose == "LFR"|| choose == "lfr") {
}
else if(choose == "CLOCK" || choose == "clock"){
}
else {
cout << "您的输入有误!请输入:FIFO、LRU、OPT、LFR、CLOCK中的一个!" << endl;
}
cout << "感谢您的使用~祝您生活愉快!" << endl;
cout << "*************************************************" << endl;
}