`
- 浏览:
11781013 次
- 性别:
- 来自:
深圳
-
STL之string,vector,algorithm常用方法
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
usingnamespacestd;
voidtestString()
...{
strings="abc",t="cde";
cout<<s+t<<endl;
s=s+'1';
cout<<s<<""<<s.size()<<endl;
cin>>s>>t;
intj=s.find(t);
if(j!=-1)
cout<<j<<endl;
else
cout<<"nofound ";
cin>>s>>t;
if(s==t)
cout<<"equal ";
elseif(s>t)
cout<<"large ";
else
cout<<"small ";
s="abcdefg";//getline(cin,s);
intk=s.find("");
if(k!=-1)
cout<<s.substr(0,k)<<""<<s.substr(k+1)<<endl;
}
voidprtVector(vector<int>v)
...{
for(inti=0;i<v.size();i++)
cout<<""<<v[i];
cout<<endl;
}
boolcmp(inta,intb)
...{
returna>b;
}
voidtestVector()
...{
intn;
cin>>n;
vector<int>v(n);
inti;
for(i=0;i<v.size();i++)cin>>v[i];
sort(v.begin(),v.end());//sort,smalltolarge
prtVector(v);
sort(v.begin(),v.end(),cmp);//sort,largetosmall
prtVector(v);
reverse(v.begin(),v.end());//reverse
prtVector(v);
fill(v.begin(),v.end(),0);//fill
prtVector(v);
intx=1,y=2;
swap(x,y);//swap
cout<<x<<""<<y<<endl;
vector<vector<int>>tv;
intr,c;
cin>>r>>c;
tv.resize(r);
for(i=0;i<r;i++)
...{
tv[i].resize(c);
for(intj=0;j<tv[i].size();j++)
cin>>tv[i][j];
}
for(i=0;i<r;i++)
...{
for(intj=0;j<tv[i].size();j++)
cout<<""<<tv[i][j];
cout<<endl;
}
tv.clear();
}
voidrun()...{
cout<<"teststring ";
testString();
cout<<" testvectorandalgorithm ";
testVector();
}
intmain()...{
run();
return0;
}
分享到:
Global site tag (gtag.js) - Google Analytics
相关推荐
4.4.3 算法(Algorithm) 53 4.4.4 函数对象(Function Object) 54 4.4.5 适配器(Adapter) 55 4.4.6 内存分配器(Allocator) 56 4.4.7 概念(Concept)和模型(Model) 56 4.5 C++ STL存在的一些问题 57 4.6 本...
本例程提供了C++的STL常用数据结构及其算法的使用范例,比如vector、string、list、forward_list、deque、queue、stack、map、set、multimap、multiset、tuple、bitset的使用范例,以及algorithm常….zip
组成的库来说提供了更好的...在C++标准中,STL被组织为下面的几个头文件:<string>、<vector>、、、<algorithm>、、、、、、、、和。文件中主要介绍了前面八个的使用,并且重点介绍了他们的属性和一些成员函数的使用。
组成的库来说提供了更好的...在C++标准中,STL被组织为下面的几个头文件:<string>、<vector>、、、<algorithm>、、、、、、、、和。文件中主要介绍了前面八个的使用,并且重点介绍了他们的属性和一些成员函数的使用。
组成的库来说提供了更好的...在C++标准中,STL被组织为下面的几个头文件:<string>、<vector>、、、<algorithm>、、、、、、、、和。文件中主要介绍了前面八个的使用,并且重点介绍了他们的属性和一些成员函数的使用。
STL本例程提供了C++的STL常用数据结构及其算法的使用范例,为面试笔试编程题提供便利
4.4.3 算法(Algorithm) 53 4.4.4 函数对象(Function Object) 54 4.4.5 适配器(Adapter) 55 4.4.6 内存分配器(Allocator) 56 4.4.7 概念(Concept)和模型(Model) 56 4.5 C++ STL存在的一些问题 57 4.6 本...
count(),存在于vector和string中,分别对单个数字和单个字符计数 用法 string mainString = Let life be beautiful like summer flowers,death like autumn leaves; int total = count(mainString.begin(), ...
4.4.3 算法(Algorithm) 53 4.4.4 函数对象(Function Object) 54 4.4.5 适配器(Adapter) 55 4.4.6 内存分配器(Allocator) 56 4.4.7 概念(Concept)和模型(Model) 56 4.5 C++ STL存在的一些问题 57 4.6 本...
ACM/ICPC 竞赛之 STL--STRING 38 ACM/ICPC 竞赛之 STL--STACK/QUEUE 38 ACM/ICPC 竞赛之 STL--MAP 40 ACM/ICPC 竞赛之 STL--ALGORITHM 40 STL IN ACM 41 头文件 42 线段树 43 求矩形并的面积(线段树+离散化...
Why should you use STL vector and string instead of arrays? How do you choose the right STL search or sort algorithm? What rules should you follow to ensure type-safe code? Whether you're working ...
sometimes STL algorithm is not good and it needs one traival function object(third parameter) , althrough std::bind/boost::lambda is available, but for some nest case, it is very hard to be used....
algorithm> //STL 通用算法 #include <bitset> //STL 位集容器 #include <cctype> #include <cerrno> #include <clocale> #include <cmath> #include <complex> //复数类...
#include <string> #include <algorithm> using namespace std; struct _AREA_VECTOR_STRUCT { int nAreaType;//区域类型 int nAreaID;//区域ID }; void CtestDlg::OnBnClickedButton2() { vector<_AREA_...
Fig01_25.cpp: Using function objects: Case insensitive string comparison LambdaExample.cpp: (Not in the book): rewriting Fig 1.25 with lambdas MaxSumTest.cpp: Various maximum subsequence sum ...
的string 类型一组顺序和关联容器类型比如vector list map 和set 以及在这些类型 上进行操作的一组可扩展的泛型算法generic algorithm 都是这个新标准库的特性本书 不但包括了许多新的资料而且还阐述了怎样在C++中...
#include <algorithm> //STL 通用算法 #include <bitset> //STL 位集容器 #include #include #include #include #include <complex> //复数类 #include #include #include #include #include <deque> //...
6.6 Using STL: string, vector, and complex... . . 265 6.6.1 string and basic_string<>.... . . . 265 6.6.2 vector<> in STL....... 267 6.6.3 Using complex<>...... . . . 267 6.6.4 limits and Other Useful...