练习12.26
1 #include <iostream> 2 #include <string> 3 #include <memory> 4 5 using namespace std; 6 7 int main() 8 { 9 string str; 10 allocator<string> alloc; 11 auto p = alloc.allocate(15); 12 auto q = p; 13 while (cin >> str && q != p + 15) 14 alloc.construct(q++, str); 15 const size_t size = q - p; 16 for (auto i = 0; i != size; ++i) 17 cout << p[i] << endl; 18 while (q != p) 19 alloc.destroy(--q); 20 alloc.deallocate(p, 15); 21 system("pause"); 22 return 0; 23 }
时间: 2024-10-13 04:41:39