CSTL范例大全教程.doc

上传人:罗晋 文档编号:6178164 上传时间:2020-09-18 格式:DOC 页数:16 大小:68.50KB
返回 下载 相关 举报
CSTL范例大全教程.doc_第1页
第1页 / 共16页
CSTL范例大全教程.doc_第2页
第2页 / 共16页
CSTL范例大全教程.doc_第3页
第3页 / 共16页
CSTL范例大全教程.doc_第4页
第4页 / 共16页
CSTL范例大全教程.doc_第5页
第5页 / 共16页
点击查看更多>>
资源描述

《CSTL范例大全教程.doc》由会员分享,可在线阅读,更多相关《CSTL范例大全教程.doc(16页珍藏版)》请在三一文库上搜索。

1、Sample of STLSTL范例(一)容器部分Vector-1Deque-20List-38Set-66Multiset-88Map-98Multimap-113Stack-136Queue-138Priority_queue-139Vectorconstructors#include #include #include #include using namespace std;int main () string str=Alex,John,Robert; rint(); return 0;OUTPUT:rint(); return 0;OUTPUT:,91); (ID(Watson D

2、.,82); for ( Iter = (); Iter != (); Iter+ ) Iter-display(); sort(),(); reserve#include #include using namespace std;int main () vector v(5,0); rint(); return 0;OUTPUT:rint(); return 0;OUTPUT:,91); (ID(Watson D.,82); for ( Iter = (); Iter != (); Iter+ ) Iter-display(); sort(),(); resize#include #incl

3、ude #include #include using namespace std;int main () deque d(5); for ( int i=0; i5; i+ ) di = i*2; copy(),(), ostream_iterator(cout, ); cout endl; (7,100); copy(),(), ostream_iterator(cout, ); cout endl; (4); copy(),(), ostream_iterator(cout, ); cout endl; return 0;OUTPUT:rint(); return 0;OUTPUT:ir

4、st *(3).second endl; cout endl; cout lower_bound(5): *(5) endl; cout upper_bound(5): *(5) endl; cout equal_range(5): *(5).first *(5).second endl;();OUTPUT:rint(); return 0;OUTPUT:rI+TarasTarasrint(); return 0;OUTPUT:irst - (*It).second endl; It+; irst - (*It).second endl; It+; M m3(),(); It = (); co

5、ut endl m3: endl; while ( It != () ) cout (*It).first - (*It).second endl; It+; return 0;OUTPUT:irst - (*It).second endl; It+; return 0;OUTPUT:irst (); Li != It-(); Li+ ) cout *Li ; cout endl; int n = (2); cout count of element with key 2 (0 or 1) is n endl; return 0;OUTPUT:econd ; It+; cout endl; c

6、out size of map = () endl; cout map m is () ? : not ) empty endl endl; (),(); cout After (),() endl; cout size of map = () endl; cout map m is () ? : not ) empty endl; return 0;OUTPUT:irst - ; cout (*It).second endl; It+; irst - (*It).second endl; It+; It = (4); if ( It != () ) cout element key 4 ha

7、s value (*It).second endl; else cout element key 4 not found endl; return 0;OUTPUT:irst - (*It).second endl; It+; cout m2 : endl; It = (); while ( It != () ) cout (*It).first - (*It).second endl; It+; irst - (*It).second endl; It+; irst - (*It).second endl; It+; return 0;OUTPUT:irst occurred (*It).s

8、econd time(s) endl; It+; cout endl; m12 = 123; m15 = 234; m18 = 345; It = (11); cout lower_bound(11) = (*It).first endl; It = (11); cout upper_bound(11) = (*It).first (); It+; return 0;OUTPUT:irst; It-(); It+; return 0;OUTPUT:irst - (*It).second endl; It+; irst - (*It).second endl; It+; M m3(),(); I

9、t = (); cout endl m3: endl; while ( It != () ) cout (*It).first - (*It).second endl; It+; return 0;OUTPUT:irst - (*It).second endl; It+; return 0;OUTPUT:AbaAbairst endl; low+; return 0;OUTPUT:Abaecond ; It+; cout endl; cout size of multimap = () endl; cout multimap m is () ? : not ) empty endl endl;

10、 (),(); cout After (),() endl; cout size of multimap = () endl; cout multimap m is () ? : not ) empty endl; return 0;OUTPUT:irst - (*It).second endl; It+; return 0;OUTPUT:irst - ; cout (*It).second endl; It+; irst - (*It).second endl; It+; It = (4); if ( It != () ) cout element key 4 has value (*It)

11、.second endl; else cout element key 4 not found endl; M:iterator upp = (4); cout all elements with key 4 endl; while ( It != upp ) cout (*It).first - (*It).second endl; It+; return 0;OUTPUT:irst - (*It).second endl; It+; cout m2 : endl; It = (); while ( It != () ) cout (*It).first - (*It).second end

12、l; It+; irst - (*It).second endl; It+; irst - (*It).second endl; It+; return 0;OUTPUT:irst endl; low+; return 0;OUTPUT:irst - (*It).second endl; It+; cout size of multimap m () endl; cout max_size of m () (); It+; return 0;OUTPUT:irst; It-(); It+; return 0;OUTPUT:irst; It-(); It+; return 0;OUTPUT:ir

13、st (); Li != It-(); Li+ ) cout *Li ; It+; cout endl;irst endl; low+; return 0;OUTPUT:#include #include #include #include using namespace std;int main () priority_queueint, vector, less ipq; (100); (200); (300); cout size of priority_queue ipq = () endl; cout ipq int,vector, less = ; while ( !() ) co

14、ut () ; (); cout endl endl; cout priority_queuestring,vector spq; endl; priority_queuestring,vector spq; for ( int i=1; i10; i+ ) (string(i,*); while ( !() ) cout () endl; (); return 0;OUTPUT:/ size of priority_queue ipq = 3/ ipq sring,vector = 300 200 100/ priority_queuestring,vector spq;/ */ */ */ */ */ */ */ */ *

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 科普知识


经营许可证编号:宁ICP备18001539号-1