国产精品天干天干,亚洲毛片在线,日韩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ó)家法律
巴马| 莎车县| 怀柔区| 霍林郭勒市| 奈曼旗| 永兴县| 林芝县| 临清市| 吉安县| 老河口市| 昌江| 彩票| 塘沽区| 通化县| 庆元县| 天长市| 遂平县| 邓州市| 新泰市| 建宁县| 高安市| 莆田市| 通化县| 石景山区| 金华市| 天镇县| 阿拉尔市| 墨竹工卡县| 贡嘎县| 连平县| 滁州市| 长沙县| 昆山市| 延边| 大英县| 福建省| 沙湾县| 黄石市| 深泽县| 宁乡县| 遵化市|