随笔分类 -  STL

摘要:使用map统计次数。#include #include #include #include #include using namespace std;void main(){ typedef map::iterator mit; map ma; mit it; ifstream in("in.txt"); int c=0; string str; string st; while( getline(in,str) ) { istringstream ist(str); while( ist>>st ) { it=ma.find(st); if( it!=ma.e 阅读全文
posted @ 2013-08-24 13:57 l851654152 阅读(237) 评论(0) 推荐(0)
摘要:STL处理内存主要是使用五个全局函数construct,deconstruct,construct实现:templatevoid construct(T1* p,const T2 value){new (p) T1(value);}uninitialized_fill,uninitializad_fill_n,unintialized_copy,通过trait特性,如果T是内置类型使用直接“=”,如果是自定义类型则使用construct一个个拷贝。 阅读全文
posted @ 2013-08-19 23:47 l851654152 阅读(165) 评论(0) 推荐(0)
摘要:在前面很多随笔里都有提到new对象是先分配内存然后初始化对象,主要是对operator new和placement new的使用在SGI STL中内存的分配和初始化是分开的,分配内存是使用类模板,模板参数是非类型模板参数,不过完全没有派上用场。当内存大于128byte时使用第一级空间配置器,当内存小于128byte时使用第二级空间配置器。对象的构造和析构是使用全局对象。 阅读全文
posted @ 2013-08-18 23:09 l851654152 阅读(146) 评论(0) 推荐(0)