c++ - 在C++中获取堆数组的大小

标签 c++ arrays heap-memory

<分区>

代码1:

int * a;
a=new int[222];
cout<<"the size of a is "<<sizeof(a)<<endl;

输出1:

the size of a is 8

代码2:

int * a;
a=new int[222];
cout<<"the size of a is "<<a.length()<<endl;

输出2:

error: member reference base type 'int *' is not a structure or
  union

如何获取堆数组的大小?谢谢..

最佳答案

简短的回答是,它无法做到,至少不能以可移植的方式做到。您需要以某种方式单独跟踪数组的大小(例如,在整数变量或类似变量中)。

关于c++ - 在C++中获取堆数组的大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28335742/

相关文章:

c++ - 为什么在使用 PIMPL 习语时这种类型不完整?

java - 比较字符串引用

c++ - 如何对非 .NET 应用程序/DLL 的内存使用情况进行分类?

java - LinkedList : java. lang.OutOfMemoryError:Java堆空间

c++ - isdigit() 无法将 "1"识别为数值

c++ - 在 C++ 中打印 float 的二进制表示

Java - 检查数组是否包含 3 个连续日期

javascript - 如果另一个数组被修改,则数组被修改

javascript - 简洁的javascript获取特定键的所有唯一值

c++ - 在 Cygwin 中处理 "C compiler cannot create executables"