C++编程故障处理—— conversion from ‘__gnu_cxx::__normal_iterator

本文介绍了一种常见的迭代器类型不匹配错误,即尝试将const型迭代器赋值给非const型迭代器的情况,并提供了相应的解决办法,即通过调整迭代器的类型来避免此类错误。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

报错:conversion from ‘__gnu_cxx::__normal_iterator……

原因:将const型的迭代器赋值给了非const型的迭代器。

处理:修改迭代器的类型。

[ERROR] /workspace/topic/v2/98/cpp/main.cpp: In function ‘int solution(std::vector<int>)’: /workspace/topic/v2/98/cpp/main.cpp:8:12: error: no match for ‘operator^=’ (operand types are ‘int’ and ‘__gnu_cxx::__normal_iterator<int*, std::vector<int> >’) 8 | unique ^= i; | ~~~~~~~^~~~ In file included from /usr/include/c++/10/ios:42, from /usr/include/c++/10/ostream:38, from /usr/include/c++/10/iostream:39, from /workspace/topic/v2/98/cpp/main.cpp:2: /usr/include/c++/10/bits/ios_base.h:107:3: note: candidate: ‘const std::_Ios_Fmtflags& std::operator^=(std::_Ios_Fmtflags&, std::_Ios_Fmtflags)’ 107 | operator^=(_Ios_Fmtflags& __a, _Ios_Fmtflags __b) | ^~~~~~~~ /usr/include/c++/10/bits/ios_base.h:107:48: note: no known conversion for argument 2 from ‘__gnu_cxx::__normal_iterator<int*, std::vector<int> >’ to ‘std::_Ios_Fmtflags’ 107 | operator^=(_Ios_Fmtflags& __a, _Ios_Fmtflags __b) | ~~~~~~~~~~~~~~^~~ /usr/include/c++/10/bits/ios_base.h:149:3: note: candidate: ‘const std::_Ios_Openmode& std::operator^=(std::_Ios_Openmode&, std::_Ios_Openmode)’ 149 | operator^=(_Ios_Openmode& __a, _Ios_Openmode __b) | ^~~~~~~~ /usr/include/c++/10/bits/ios_base.h:149:48: note: no known conversion for argument 2 from ‘__gnu_cxx::__normal_iterator<int*, std::vector<int> >’ to ‘std::_Ios_Openmode’ 149 | operator^=(_Ios_Openmode& __a, _Ios_Openmode __b) | ~~~~~~~~~~~~~~^~~ /usr/include/c++/10/bits/ios_base.h:189:3: note: candidate: ‘const std::_Ios_Iostate& std::operator^=(std::_Ios_Iostate&, std::_Ios_Iostate)’ 189 | operator^=(_Ios_Iostate& __a, _Ios_Iostate __b) | ^~~~~~~~ /usr/include/c++/10/bits/ios_base.h:189:46: note: no known conversion for argument 2 from ‘__gnu_cxx::__normal_iterator<int*, std::vector<int> >’ to ‘std::_Ios_Iostate’ 189 | operator^=(_Ios_Iostate& __a, _Ios_Iostate __b)
03-24
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值