stl
文章平均质量分 74
zhucai4
这个作者很懒,什么都没留下…
展开
-
set
Some basic operations for set. #include #include using 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 · 307 阅读 · 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 · 280 阅读 · 0 评论 -
sort
Use student class. #ifndef STUDENT_HPP_INCLUDED #define STUDENT_HPP_INCLUDED using namespace std; class student{ private: int NO; int Grade; string Name; public: student():NO(0),G原创 2015-03-18 19:45:00 · 333 阅读 · 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 · 460 阅读 · 0 评论 -
string
Use stringstream #include #include #include #include using namespace std; template void printInfo(T& s){ for(auto itr=s.begin(); itr!=s.end(); ++itr){ cout << *itr << ' '; }原创 2015-06-24 09:59:20 · 397 阅读 · 0 评论 -
list
Some basic operation for stl list.#include #include using 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 · 316 阅读 · 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 · 737 阅读 · 0 评论 -
swap
If we use containers, such as vector, the two for swap do not need to be of same length, #include #include #include #include using namespace std; int main(){ vectorv1{10,20,30}; vectorv2{1原创 2015-06-25 16:16:23 · 580 阅读 · 0 评论 -
transform
Use student class, for each student, add extra 5 points to its grade. #ifndef STUDENT_HPP_INCLUDED #define STUDENT_HPP_INCLUDED using namespace std; class student{ private: int NO; int Grad原创 2015-03-18 15:51:42 · 273 阅读 · 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 · 373 阅读 · 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_INCLUDED using namespace std; class student{ private:原创 2015-03-18 18:32:19 · 359 阅读 · 0 评论 -
copy
Examples. Still use student class. #ifndef STUDENT_HPP_INCLUDED #define STUDENT_HPP_INCLUDED using namespace std; class student{ private: int NO; int Grade; string Name; public: st原创 2015-03-18 14:54:47 · 330 阅读 · 0 评论 -
Queue and Stack
Basic operations for queue and stack. #include #include #include #include #include #include using namespace std; template void printStack(stack s){ while(!s.empty()){ cout << s.top(原创 2015-03-15 15:32:29 · 320 阅读 · 0 评论 -
deque
Use adaptor design pattern and deque in stl library, get a first-in-first-out queue. #include #include using namespace std; template class MyQueue{ private: deque d; public: MyQueue(){};原创 2015-03-15 10:10:10 · 261 阅读 · 0 评论 -
map
Some basic operations for map in stl. #include #include using 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 · 323 阅读 · 0 评论 -
smart pointer
Following examples of book .#include #include #include #include using namespace std; int main(){ shared_ptr pNico(new string("nico")); shared_ptr pJutta(new string("jutta")); (*pNico)[0]原创 2015-03-16 11:26:04 · 347 阅读 · 0 评论 -
vector
Some example for stl vector. #include #include #include using namespace std; class Student{ public: string strNO; string strName; string strSex; string strDate; Student(string原创 2015-03-13 19:43:27 · 290 阅读 · 0 评论 -
function object
Function Objects in STL.原创 2015-03-13 00:42:27 · 414 阅读 · 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 · 243 阅读 · 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 · 295 阅读 · 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 · 272 阅读 · 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 · 560 阅读 · 0 评论