我想用一個指針我有下面的示例代碼中插入新元素放入vector
:如何通過指針訪問矢量?
struct info {
string Name;
int places; // i will use the binary value to identfy the visited places example 29 is 100101
// this means he visited three places (London,LA,Rome)
vector<int> times; // will represent the visiting time,e.g. 1,2,5 means london 1 time, LA
// twice and Rome five times
};
map<string,vector<info> *> log;
Peaple是從不同的城市來了,我會如果城市存在的檢查,只是新的人加入到vector
,否則創造一個新的地圖對象:
vector<info> tp;
info tmp;
if(log.size()==0|| log.count(city)==0) //empty or not exist
{
tp.push_back(tmp);
vector<info>* ss = new vector<info>;
ss=&(tp);
// create a new object
log.insert(map<string,vector<info> * >::value_type(city,ss)); // new object
}
else // city exist, just add the information to the vector
{
map<string,vector<info> *>::iterator t;
t=log.find(city);
*(t->second).push_back(tmp); //the problem in this line
}
我怎樣才能將新的TMP到載體?
的信息進行讀取,如下所示:
Paris,Juli,5,3,6
Paris,John,24,2
Canberra,John,4,3
London,Mary,29,4,1,2
你提到的問題是在某一行,但從來沒有解釋是什麼問題。它是什麼? –
刪除你程序中的所有星號,然後修改它來編譯。你會好很多。 – avakar
你是否建議他停止使用指針?請解釋... – mtsvetkov