stl
文章平均质量分 74
zhucai4
这个作者很懒,什么都没留下…
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
set
Some basic operations for set.#include#includeusing namespace std;int main(){ int a[] = {5, 3, 9, 3, 7, 2, 9, 3}; set s(a, a+sizeof(a)/sizeof(int)); set::iterator itr = s.begin();原创 2015-03-15 22:48:20 · 336 阅读 · 0 评论 -
replace
Simple example#include #include #include #include using namespace std;int main(){ vector v({1,2,3,4,5,4,3,2,1}); cout << "Original Vector: " << endl; auto itr = v.begin(); whi原创 2015-03-18 16:27:28 · 314 阅读 · 0 评论 -
sort
Use student class. #ifndef STUDENT_HPP_INCLUDED#define STUDENT_HPP_INCLUDEDusing namespace std;class student{private: int NO; int Grade; string Name;public: student():NO(0),G原创 2015-03-18 19:45:00 · 378 阅读 · 0 评论 -
exception
Simple example for defining users' own exception. The key point is to implement pure virtual function what().#include #include using namespace std;class myexception : public exception {publi原创 2015-03-20 17:19:43 · 520 阅读 · 0 评论 -
string
Use stringstream#include #include #include #include using namespace std;templatevoid printInfo(T& s){ for(auto itr=s.begin(); itr!=s.end(); ++itr){ cout << *itr << ' '; }原创 2015-06-24 09:59:20 · 442 阅读 · 0 评论 -
list
Some basic operation for stl list.#include#includeusing namespace std;template void print(T& l){ typedef typename T::iterator Titerator; Titerator itr = l.begin(); while(itr!=l.end()原创 2015-03-15 11:27:15 · 353 阅读 · 0 评论 -
lambda function
A lambda is an ad-hoc, locally-scoped function. Basically, lambdas are syntactic sugar, designed to reduce a lot of the work required in creating ad-hoc functor classes,The brackets ([]) mark th原创 2015-06-24 11:33:57 · 830 阅读 · 0 评论 -
swap
If we use containers, such as vector, the two for swap do not need to be of same length,#include#include#include #includeusing namespace std;int main(){ vectorv1{10,20,30}; vectorv2{1原创 2015-06-25 16:16:23 · 626 阅读 · 0 评论 -
transform
Use student class, for each student, add extra 5 points to its grade.#ifndef STUDENT_HPP_INCLUDED#define STUDENT_HPP_INCLUDEDusing namespace std;class student{private: int NO; int Grad原创 2015-03-18 15:51:42 · 312 阅读 · 0 评论 -
STL Application 1
(1) class hierarchy(2) polymorphism, pointer of base class(3) function object#include #include #include using namespace std;class Shape{public: virtual void Draw() = 0; virtua原创 2015-06-30 19:35:41 · 440 阅读 · 0 评论 -
remove
use student class, remove students from collection, if his grade is less than 80.student class#ifndef STUDENT_HPP_INCLUDED#define STUDENT_HPP_INCLUDEDusing namespace std;class student{private:原创 2015-03-18 18:32:19 · 389 阅读 · 0 评论 -
copy
Examples. Still use student class.#ifndef STUDENT_HPP_INCLUDED#define STUDENT_HPP_INCLUDEDusing namespace std;class student{private: int NO; int Grade; string Name;public: st原创 2015-03-18 14:54:47 · 365 阅读 · 0 评论 -
Queue and Stack
Basic operations for queue and stack. #include#include#include#include#include#includeusing namespace std;template void printStack(stack s){ while(!s.empty()){ cout << s.top(原创 2015-03-15 15:32:29 · 373 阅读 · 0 评论 -
deque
Use adaptor design pattern and deque in stl library, get a first-in-first-out queue.#include#includeusing namespace std;template class MyQueue{private: deque d;public: MyQueue(){};原创 2015-03-15 10:10:10 · 296 阅读 · 0 评论 -
map
Some basic operations for map in stl.#include#includeusing namespace std;int main(){ map mymap; pair s1(1, "Tim"); pair s2(2, "Sam"); pair s3(6, "David"); pair s4(5, "James")原创 2015-03-16 08:31:53 · 353 阅读 · 0 评论 -
smart pointer
Following examples of book .#include#include#include#includeusing namespace std;int main(){ shared_ptr pNico(new string("nico")); shared_ptr pJutta(new string("jutta")); (*pNico)[0]原创 2015-03-16 11:26:04 · 378 阅读 · 0 评论 -
vector
Some example for stl vector.#include#include#includeusing namespace std;class Student{public: string strNO; string strName; string strSex; string strDate; Student(string原创 2015-03-13 19:43:27 · 325 阅读 · 0 评论 -
function object
Function Objects in STL.原创 2015-03-13 00:42:27 · 473 阅读 · 0 评论 -
for_each
Example#include #include #include #include using namespace std;class summaryInfo{public: summaryInfo():nsum(0),ncount(0){} int getSum(){ return nsum; } int getMin(){ return nmin;原创 2015-03-18 10:06:27 · 340 阅读 · 0 评论 -
search
Simple example#include #include #include #include using namespace std;int main(){ vector v({1,2,2,2,3,4,4,5,6,7,1,2,2,3}); auto itr = v.begin(); cout << "Original vector: " << end原创 2015-03-18 11:03:16 · 325 阅读 · 0 评论 -
count
One simple example.#include #include #include #include using namespace std;int main(){ vector v({2, 0, 4, 6, 0, 3, 1, -7}); int num = count(v.begin(), v.end(), 0); cout << "The nu原创 2015-03-18 11:59:05 · 294 阅读 · 0 评论 -
adjacent_find
Protype of function is template ForwardIterator adjacent_find( ForwardIterator _First, ForwardIterator _Last );template ForwardIterator adjacent_find( ForwardIterat原创 2015-07-05 19:34:55 · 619 阅读 · 0 评论
分享