随笔分类 - STL代码
STL代码
摘要:1 #include //双向循环链表 2 #include 3 #include 4 using namespace std; 5 int main() 6 { 7 list L; 8 L.push_back(2); 9 L.push_back(1);10 L.push_back(5);11 //尾部元素扩张12 L.push_front(8);13 //头部元素扩张14 list::iterator it;15 it=L.begin();16 L.insert(++it,2);//中间插入;17 for(it=L.begin();it!=L...
阅读全文
摘要:#include //包含了set类#include #include using namespace std;struct Info{ string name; float score; bool operator(const Info &a)const// greater模版需要写上这个操作符重载 { return score>a.score;//保证了按score降序排列 } bool operator==(const Info &d)const//find会用==操作符重载进行比较 { return score==d.score; }};int main(...
阅读全文
摘要:1 #include 2 #include //大概是字符串流 3 #include 4 using namespace std; 5 6 //c++方法 将double数值 转换成string对象 7 string convertToString(double x) 8 { 9 ostringstream o;10 if(o>x)//很像c语言里面的sscanf 从流中第一个字符开始分流出一个double22 return x;23 else24 return 0.0;25 }26 int main()27 {28 string a,e;29 c...
阅读全文
摘要:#include //包含string类#include #include #include #include //#include //字符串流using namespace std;int main(){ string a,b; char c[10]="拜拜"; a="ab c";//把c字符串赋值给string对象 a.append(c);//把字符或者字符串 追加到string对象的最后 很像vetor的push_back()方法; b+=a+c; cout v; v.push_back(c); v.push_back(a); cout<&
阅读全文
摘要:1 #include //包含cin cout 2 #include //包含向量 vector 3 #include //包含算法 accumulate 4 #include //包括stl的很多算法 5 #include 6 using namespace std; 7 bool cmp(const int &a,const int &b)//这里参数类型要是const型的 8 { 9 if(a!=b)//这里判断的意思就是说 如果a>b 结果就为真 否则就为假10 return a>b;11 else12 return a>b;13 }14 int ma
阅读全文