我想用一个指针我有下面的示例代码中插入新元素放入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