C++ STL string与算法
生活随笔
收集整理的這篇文章主要介紹了
C++ STL string与算法
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
代碼如下:
#define _SCL_SECURE_NO_WARNINGS#include <iostream> #include <string> //要與c語言里面的#include <string.h>區分 #include <algorithm> #include <functional>using namespace std;void fun(char c){cout << c; }int main(){string str("fasdfawefwwqaaaazzz");for_each(str.begin(), str.end(),fun);cout << endl;sort(str.begin(), str.end()); //默認從小到大排序for_each(str.begin(), str.end(), fun);cout << endl;//從大到小排序sort(str.begin(), str.end(), greater<char>());for_each(str.begin(), str.end(), fun);cout << endl;system("pause");return 0; }運行結果如下:
總結
以上是生活随笔為你收集整理的C++ STL string与算法的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Python工作笔记-往dll中传入ch
- 下一篇: Qt工作笔记-QTableWidget插