参考文献《大道至简:C++STL》
- new/delete
#include#include using namespace std; int main() { int size; cin >> size; int * arr = new int[size]; for(int i = 0; i < size; i++) { arr[i] = rand(); } for(int i = 0; i < size; i++) { cout << arr[i] << " "; } cout << endl; delete[] arr; return 0; }
- auto_ptr
#include#include #include using namespace std; int main() { auto_ptr str1(new string("okokok!")); auto_ptr str2(str1); auto_ptr str3(new string("str3")); cout << str1.get() << endl; //0 cout << str2.get() << endl; //0x632270 cout << str3.get() << endl; //0x6322c0 cout << *str2 << endl; cout << *str3 << endl; return 0; }
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)