日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 >

迭代器的使用实例

發(fā)布時間:2025/5/22 36 豆豆
生活随笔 收集整理的這篇文章主要介紹了 迭代器的使用实例 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
//統(tǒng)計字符 #include <vector> #include<iostream> #include<string> #include<cctype> #include <algorithm> using namespace std;int main() {string str;vector<int> v;vector<int>::iterator iter = v.begin();getline(cin, str);int len = str.size(), letter_n = 0, digit_n = 0, space_n = 0;for (int i = 0; i<len; i++){if (isalpha(str[i]))letter_n++;else if (isdigit(str[i]))digit_n++;else if (isspace(str[i]))space_n++;}v.push_back(letter_n);v.push_back(digit_n);v.push_back(space_n);/* for (iter = v.begin(); iter != v.end(); iter++)cout << *iter<<',';cout << endl; */ //普通迭代器輸出sort(v.rbegin(), v.rend(), less<int>());cout << "反向迭代器輸出: " << endl;vector<int>::reverse_iterator it = v.rbegin();while (it != v.rend()){cout << *it << " ";++it;}return 0; }

總結(jié)

以上是生活随笔為你收集整理的迭代器的使用实例的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。