0
可视化:
NTlist:[NTstring,RHSlist] < - > [NTstring,RHSlist] < - > [NTstring,RHSlist] ...C++列表迭代不访问列表的内容
Ntlocation“点”,比如说,中间链接^(上面),因为这里的NTstring匹配我正在搜索的内容。
我想要做什么:
使用NTlocation “指针” 我想访问和修改此处的RHSlist。
问题:
Debugger shows RHSlist data being put into NTlocation
But I want RHSlist data to be in element of NTlist
非常感谢您的帮助!
编辑。每个请求添加代码。再次感谢!
typedef struct RHSnode {
token_type type;
string token;
} RHSnode;
typedef struct NTnode {
token_type type;
string token;
list<RHSnode> RHSlist;
} NTnode;
int function {
list<NTnode> NTlist;
list<NTnode>::iterator NTlocation;
freopen("example.txt", "r", stdin);
t_type = getToken(); //this function gets tokens from txt file above
// code has been simplified for your viewing pleasure
// but basically NT.list is created for each token listed at start of
// text file in the following manner. (This works fine)
NTnode entry;
entry.token = string(current_token);
NTlist.push_back(entry);
t_type = getToken();
// loop until all tokens are read
{
t_type = getToken();
string NTstring = string(current_token);
NTlocation = searchNTList(NTstring, NTlist);
RHSnode entry;
entry.token = string(current_token);
//****Here is the problem:
NTlocation->RHSlist.push_back(entry);
}
return 1;
}
list<NTnode>::iterator searchNTList(string NTstring, list<NTnode> &NTlist){
list<NTnode>::iterator NTlocation = NTlist.end(); //"past-the-end" indications search failure
list<NTnode>::iterator iterator = NTlist.begin();
for (; iterator != NTlist.end() ; iterator++){
if (iterator->token.compare(NTstring) == 0){
NTlocation = iterator;
break;
}
}
return NTlocation;
}
显示代码,散文是徒劳! –
你的问题中也有大量的代码。你的问题是否有必要?你能把它缩小到还能再现问题的最小量吗? –
@BillLynch感谢您查看代码。它已被简化。很尊重你,先生。 – mtnMan