using ContactModel = struct _ContactModel {
std::string sex;
std::string city;
std::string account;
std::string remarks;
};
std::map<int, std::vector<ContactModel>> m_map;
void test( ) {
ContactModel m;
std::vector<ContactModel> models;
models.push_back(m);
m_map[0] = models; //報錯
}
這個要怎么改正呢?
uj5u.com熱心網友回復:
首先要明確它報的是什么錯,編譯錯誤的資訊能否復制上來看看?但是,在我的編譯器上顯示這樣沒有任何問題。比方說:
#pragma GCC optimize(2)
#include<bits/stdc++.h>
using namespace std;
map<vector<int>,int> p; //vector 作為陣列下標
map<int,vector<int> >q; //vector 作為映射型別
inline int read(){char ch=getchar();int f=1;while(ch<'0' || ch>'9') {if(ch=='-') f=-f; ch=getchar();}
int x=0;while(ch>='0' && ch<='9') x=(x<<3)+(x<<1)+ch-'0',ch=getchar();return x*f;}
// read 函式是讀入一個 int 型別的數
int main(){
vector<int> v; v.push_back(read());
p[v]=read(); q[read()]=v; //映射
return 0;
}
然而編譯沒有任何問題,即通過編譯。
那你報的應該不是編譯錯誤吧?(如果是,就是編譯器不同的緣故,這個我無法幫助了)
如果是運行錯誤的話,你可以試試把
using ContactModel = struct _ContactModel
改成:
struct ContactModel (因為本人一直習慣于這樣子寫)
如果還不行,在前面加上一條:
using namespace std;
然后把所有的 "std::" 都刪去。
再試試,如果還不行的話,那我也不知道是什么問題了。。
希望能得到幫助,也希望自己能得到專家分吧。
uj5u.com熱心網友回復:
頂上去
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/87371.html
標籤:C++ 語言
上一篇:新手實作雙向鏈表的疑惑
下一篇:求助,急!!!C語言初級
