程序博客网 > linux统计文件数量
来源:互联网 发布:linux统计文件数量 编辑:程序博客网 时间:2024/04/27 23:02
#include<iostream>#include <vector>using namespace std;void main(){int beg,len;//子串开始位置,长度vector<char> cvec;//声明容器char temp;while (cin.get(temp))cvec.push_back(temp);//添加元素cout<<"Please input the starting position and the length of substring/n";cin.clear();//恢复流状态cin>>beg>>len;if((beg+len)>cvec.size())//判断求子串的输入是否有误{cout<<"Wrong Input!"<<endl;return ;}for (vector<char>::iterator iter=cvec.begin()+beg-1;iter!=cvec.begin()+beg+len-1;iter++)//输出子串cout<<*iter;cout<<endl;}//*********Andy于2010/7/7*******************************
看到有个同学求子串的程序写的有点乱,就自己动手写了一个如上。用STL实现,相当简洁