#include <iostream>
#include <algorithm>
//using namespace std;
using std::cin;
using std::cout;
using std::endl;
template <typename T>
void increaseSize(T*& A, int oldsize, int newsize)
{
if (oldsize < 0 || newsize < 0 || oldsize > newsize) throw " ";
T* temp = new T[newsize];
std::copy(A, A + oldsize, temp);
delete[] A;
A = temp;
}
int main()
{
int* a = new int[10]{ 1,2, 3, 4, 5, 6, 7,8,9 };
char* A = new char[5]{ 'c', 'y','u','p','j' };
int result = sizeof(a);//4 指向int的指针 (地址)所占的内存大小
result = sizeof(A) / sizeof(A[0]);//1
increaseSize(A, 5, 10);
//如何获取数组A的尺寸 10?
delete[] a;
delete[] A;
cout << endl << "ok" << endl;
return 0;
}
动态创建的数组 char* A = new char[5]{ 'c', 'y','u','p','j' }; 如何获取其长度
最新推荐文章于 2024-05-03 00:27:26 发布