Re: [問題] 三維map的find要怎麼做?
: 我想用map把一個int清單(vector<int>) 存在一個三維空間中
: 希望用 mymap[x][y][z] 可以對應到一個 vector<int>
: 但是現在有個問題是,我想要確認某(x0,y0,z0)位置是不是已經建立清單了
: 如果不是的話要生一個vector給它
: 網路上有查了find的用法,但是找不到類似問題的解決方法
: map生成如下,請問各位,find或有什麼方法能做到這件事?
: map<int, map<int, map<int, vector<int> > > > mymap;
using namespace std;
typedef map<int,map<int,map<int,vector<int> > > > mymap;
bool create(mymap &m,int x,int y,int z){
if(m[x][y].find(z)==m[x][y].end()){
vector<int> input;
m[x][y][z] = input;
return true;
}
else{
return false;
}
}
int main(int argc,char* argv[]){
mymap m;
if(create(m,1,1,1)==true){
cout << "Vector doesn't exist, and create one" << endl;
}
else{
cout << "Vector already exist." << endl;
}
if(create(m,1,1,1)==true){
cout << "Vector doesn't exist, and create one" << endl;
}
else{
cout << "Vector already exist." << endl;
}
return 0;
}
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 220.133.16.181
※ 文章網址: https://www.ptt.cc/bbs/C_and_CPP/M.1483773191.A.73A.html
推
01/07 16:42, , 1F
01/07 16:42, 1F
→
01/07 16:42, , 2F
01/07 16:42, 2F
→
01/07 16:50, , 3F
01/07 16:50, 3F
→
01/07 16:50, , 4F
01/07 16:50, 4F
推
01/07 16:55, , 5F
01/07 16:55, 5F
→
01/09 17:06, , 6F
01/09 17:06, 6F
討論串 (同標題文章)
本文引述了以下文章的的內容:
完整討論串 (本文為第 2 之 2 篇):