国产精品天干天干,亚洲毛片在线,日韩gay小鲜肉啪啪18禁,女同Gay自慰喷水

歡迎光臨散文網(wǎng) 會(huì)員登陸 & 注冊(cè)

c++ 返回vector中元素的下標(biāo)

2023-08-18 16:16 作者:Euler_Formula  | 我要投稿

返回vector中元素的下標(biāo): ```c++ #include #include int main() { ??std::vector v = {10, 20, 30, 40, 50}; ??// 返回元素為40的下標(biāo) ??auto it = std::find(v.begin(), v.end(), 40); ??int index = std::distance(v.begin(), it); ??std::cout << "Index of 40: " << index << std::endl; ??// 返回元素為20的下標(biāo) ??it = std::find(v.begin(), v.end(), 20); ??index = std::distance(v.begin(), it); ??std::cout << "Index of 20: " << index << std::endl; ??return 0; } ``` 輸出: ``` Index of 40: 3 Index of 20: 1 ``` 這里使用了`std::find`函數(shù)尋找元素的迭代器,并使用`std::distance`函數(shù)計(jì)算該迭代器與vector起始迭代器之間的距離,即該元素在vector中的下標(biāo)。

c++ 返回vector中元素的下標(biāo)的評(píng)論 (共 條)

分享到微博請(qǐng)遵守國(guó)家法律
龙井市| 九江县| 天等县| 深州市| 金寨县| 绥棱县| 仪征市| 虎林市| 金平| 张家界市| 英山县| 宝山区| 吴忠市| 香格里拉县| 天等县| 丰宁| 海口市| 东乌| 乌审旗| 祥云县| 龙南县| 天祝| 三亚市| 公主岭市| 张掖市| 丰都县| 朔州市| 巫溪县| 巴塘县| 乡宁县| 电白县| 读书| 赤壁市| 衡南县| 两当县| 惠安县| 若尔盖县| 崇礼县| 福建省| 武穴市| 湄潭县|