
c++ 学习笔记
某日暮光
这个作者很懒,什么都没留下…
展开
-
c++ vector指针访问vector元素的方法
c++使用 vector指针访问vector元素时,不能简单的类似于c中数组和指针的方式。需要使用迭代器。int main(){ vector s; vector *p = &s; s.push_back(1); for (vector::iterator it = p->begin(); it != p->end(); it++) cout << *it<<endl; //原创 2017-07-12 10:28:02 · 41575 阅读 · 5 评论 -
数组方式赋值字符串及字面值常量赋值字符串的区别
c++实验笔记。数组赋值字符串时需要显示'\0',否则在某些时候会有问题。int main(){ const char a[] = {'a','v','b','b','\0'}; //数组需要显示的以\0结尾, //否则循环不会终止 const char b[] = "avbb";原创 2017-07-14 15:02:58 · 627 阅读 · 0 评论 -
STL:: allocator之deallocate & destory的区别与联系
c++中的allocator是标准库中的一个类,负责内存分配管理。下面是《STL源码剖析》中一个简单allocator实现的部分源代码:deallocate: template inline void _deallocate(T* buffer) { ::operator delete(buffer); //为什么不用 delete [] ? ,operator原创 2017-07-28 14:34:30 · 2995 阅读 · 2 评论 -
allocator简单实现
allocator是c++标准库中用于管理内存的一个类。主要包括以下类方法:代码如下(来源于《STL源码剖析》):#ifndef _JJALLOC_#define _JJALLOC_#include //for placement new#include #include #include #include namespace JJ{ template原创 2017-07-28 16:07:10 · 811 阅读 · 0 评论