⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.cpp

📁 《C++ STL开发技术引导》配套光盘 聆听大师级的指点
💻 CPP
字号:
#include <memory>
#include <iostream>
using namespace std;

class A{
public:
	A(int i_):i(i_){}
	operator int() const { return i; }  //转换为int打印
private:
	int i;
};

int main(void){
	//分配10个对象空间
	allocator<A> alloc;
	A* p=alloc.allocate(10);  
	//用原始存储迭代器赋值
	int i;
	raw_storage_iterator<A*, A> rsi(p);
	for(i=0; i<10; i++)
		*rsi++=A(i);
	//打印
	for(i=0; i<10; i++)
		cout << static_cast<int>(*p++) << " ";
	//释放空间
	alloc.deallocate(p, 10);  
	return 0;
}


 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -