Hello ALL,
I have a vector
vector<CLUSTER> ClustList; where
struct CLUSTER{
string DocID_DocName;
}
some members of CLUSTER have been ignored for simplicityInitially, I put 3 elements into ClusterList by using push_back()
the content in DocID_DocName is shown below.
ClusterList[0].DocID_DocName = "0";
ClusterList[1].DocID_DocName = "1";
ClusterList[2].DocID_DocName = "2";
In the following program snippet, I want to update the content of ClusterList[0].DocID_DocName, ClusterList[1].DocID_DocName and ClusterList[2].DocID_DocName
with iterator
vector<CLUSTER>::iterator it;
for(it = ClusterList.begin(); it != ClusterList.end(); it++)
{
// do mapping, so that I get DocName according to DocID
// DocID DocName
// 0 NewsTilte.txt
// 1 NewsProvider.txt
// 2 NewsUser.txt
String Str //mapping result is stored into Str
(*it).DocID_DocName = Str;// cause segment fault.
}
The statement
(*it).DocID_DocName = Str;
caused segment fault.
The length of Str is longer than that of the origianl content.
But, I still cannot figure out the reason.
Please help. Thanks