可能重複: Is there any way to determine the size of a C++ array programmatically? And if not, why? 我可以用C++動態分配的數組的長度,如果沒有,請問C++的delete運算符知道有多少元素自由。 我搜索了論壇,發現對於動態分配的數組,長度存儲在數組標題之前的四個字節或其他地方。我怎樣才能得到這個價值?
我新的C++和我有什麼不清楚: #include <iostream>
using namespace std;
double* foo(void)
{
double* b = new double[100];
return b;
}
int main()
{
double* a = foo();
delete [] a;
ret
我想刪除一個char *數組,這應該是簡單的吧? char * = new char[length];然後用delete[] char;? 另外,本人練習無法使用std::string。 我得到這個錯誤: HEAP CORRUPTION DETECTED: after Normal block (#137) 0x00794B50. CRT detected that the application
這是一個很簡單的問題(或者至少乍一看)。讓我們說我們有以下步驟: void procedure(void)
{
int x = new int;
x=42;
}
當我打電話這個程序在我的程序中應該導致所謂的內存泄漏,對嗎?我在處理一個小項目時遇到過這樣的錯誤,然後編譯器輸出類似如下內容:檢測到內存泄漏。嘗試模擬內存泄漏,看看什麼編譯器的輸出,但它根本沒有抱怨(我