reallocate.cpp
来自「1. 系统概述: 图书馆管理系统是运行于Windows系统下的应用软件」· C++ 代码 · 共 16 行
CPP
16 行
#include<algorithm> // for std::copy
//类型指定!!
#include"Class/Reader.h"
typedef CReader ElemType;
bool reallocate(ElemType* &p, int &size, int addsize) //重新分配内存,成功true,失败false
{
size += addsize; //double the array''s size with each reallocation
ElemType * temp = new ElemType [size];
if (temp == NULL)return false;
std::copy(p, p+(size-addsize), temp);
delete [] p; // release original, smaller buffer
p=temp; // reassign p to the newly allocated buffer
return true;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?