<分区>
Possible Duplicate:
Is there any way to determine the size of a C++ array programmatically? And if not, why?
我能否在 C++ 中获取动态分配数组的长度,如果不能,C++ 的删除运算符如何知道要释放多少元素。
我搜索了论坛,发现对于动态分配的数组,长度存储在数组头之前的四个字节或其他地方。我怎样才能得到这个值?
<分区>
Possible Duplicate:
Is there any way to determine the size of a C++ array programmatically? And if not, why?
我能否在 C++ 中获取动态分配数组的长度,如果不能,C++ 的删除运算符如何知道要释放多少元素。
我搜索了论坛,发现对于动态分配的数组,长度存储在数组头之前的四个字节或其他地方。我怎样才能得到这个值?
最佳答案
header 前的四个字节绝对是您不应该使用的实现细节。如果您需要知道数组的大小,请使用 std::vector。
关于c++ - 有没有办法在 C++ 中获取动态分配数组的长度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7484442/