c++学习练习
来源:互联网 发布:python网络爬虫源码 编辑:程序博客网 时间:2024/06/06 14:05
1、创建string文本:
sdsd haha hehe alala xixi hehe sdsfddf haha ninin
练习程序:
#include <iostream>#include <algorithm>#include <vector>#include <string>#include <fstream>#include <sstream>#include <list>#include <cstdlib>using namespace std;bool isshorter(const string& s1, const string& s2);int main(int argc, char *argv[]){list<string> ilist;list<string>::iterator ite;vector<string> vec;vector<string>::iterator vte; ifstream infile("./string", ifstream::in);if(!infile){perror("read file error");}string s,sword;while(getline(infile, s)){istringstream istring(s);while(istring >> sword){ilist.push_back(sword);}}vec.assign(ilist.begin(), ilist.end());for(ite = ilist.begin(); ite != ilist.end(); ++ite){cout << *ite << endl;}cout << "----------------" << endl;ilist.sort();for(ite = ilist.begin(); ite != ilist.end(); ++ite){cout << *ite << endl;} ilist.unique();cout << "----------------" << endl;for(ite = ilist.begin(); ite != ilist.end(); ++ite){cout << *ite << endl;} cout << ilist.size() << endl; cout << "++++++++++++++++++++++++++++++" <<endl;sort(vec.begin(), vec.end());for(vte = vec.begin(); vte != vec.end(); ++vte){cout << *vte << endl;}cout << "----------------" << endl;stable_sort(vec.begin(), vec.end(), isshorter);for(vte = vec.begin(); vte != vec.end(); ++vte){cout << *vte << endl;}cout << "----------------" << endl;vte = unique(vec.begin(), vec.end());vec.erase(vte, vec.end());for(vte = vec.begin(); vte != vec.end(); ++vte){cout << *vte << endl;}cout << "----------------" << endl; return 0;}bool isshorter(const string& s1, const string& s2){return s1.size() > s2.size(); }
0 0
- Objective-C学习练习
- 学习c编程练习1
- C 学习笔记: 移位操作练习。
- 学习C语言是否要天天练习?
- C语言学习第三天(练习)
- C语言学习第十三天(练习)
- C语言学习第十四天(练习)
- 学习Objective-C程序设计 第七章练习
- 学习C语言的一些小练习
- 啊哈C——学习2.2练习
- 啊哈C——学习2.3练习
- 啊哈C——学习2.4练习
- 啊哈C——学习2.5练习
- 啊哈C——学习2.6练习
- 啊哈C——学习2.7练习
- 啊哈C——学习2.8练习
- 啊哈C——学习2.10练习
- 啊哈C——学习3.2练习
- Linux笔记(三)-Linux各目录的作用及服务器注意事项
- LeetCode 198
- 第一章 C++编程基础(对象的定义和初始化)
- 软件公司职责分配
- c语言接口处理函数
- c++学习练习
- WPS:一键加密
- IntentService说明
- Linux下C语言操作数据库
- IOS 开发进阶--多线程和网络--NSURLSession详细解
- 如何生成Android的debug使用的keystore
- Invocation of init method failed; nested exception is java.io.FileNotFoundException: class path reso
- unity中xml读取
- Window7安装Perl的Image-Magick模块