The Scoped_array class template stores a pointer to a dynamically allocated array.
The Scoped_array class template stores a pointer to a dynamically allocated array that automatically reconstructs the memory used on the heap (heap).
Header files: #include <boost/scoped_array.hpp>
Code:
* * * test.cpp * * Created on:2014.04.18 *
author:spike/
/*eclipse CDT, gcc 4.8.1* /
#include <iostream>
#include <boost/scoped_array.hpp>
using namespace std;
int main () {
const int n (3);
Boost::scoped_array<int> PData (new int[n*n]);
int temp[9] = {0, 1, 2, 3, 4, 5, 6, 7, 8};
Pdata.reset (temp);
For (std::size_t i=0 i<n*n; ++i) {
std::cout << "pdata[" << i << "] =" << Pdata[i] <& Lt Std::endl;
}
return 0;
}
Output:
Pdata[0] = 0
pdata[1] = 1
pdata[2] = 2
pdata[3] = 3
pdata[4] = 4
pdata[5] = 5
pdata[6] = 6
pDa TA[7] = 7
pdata[8] = 8
Author: csdn Blog spike_king
More Wonderful content: http://www.bianceng.cnhttp://www.bianceng.cn/Programming/cplus/