【C++】使用unordered_map>遇到问题

amantuer CSDN会员 amantuer 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区

vector<int> partitionLabels(string str) {
unordered_map<char,pair<int,int>>hash;
for(int i=0;i<str.length();i++){
if(hash.find(str[i]) == hash.end()){
hash.insert({str[i],{i,i}});
}else{
hash[str[i]].second = i;
}
}
vector<int>ans;
for(int i=0;i<hash.size();i++){
int clidx=hash[i].second.second;

最后一行报错如下,请教各位大佬如何解决?我就是想把pair的第二值取出来赋值给int变量clidx。

Line 14: Char 39: error: member reference base type 'int' is not a structure or union
int clidx=hash[i].second.second;
~~~~~~~~~~~~~~^~~~~~~
...全文

相关推荐

评论 4
收藏 已收藏
分享
返回顶部
amantuer CSDN会员
C++ 语言 65,214 成员 250,514 内容