BUG:Run-Time Check Failure #2 - Stack around the variable 'a' was corrupted.
Why?
#include <iostream>
int main()
{
char a[] = "hello";
a[6] = 'A';
std::cout << a;
system("pause");
return 0;
}
問題處在代碼的下一行。數組a,在STACK上內存分配成功,但是操作超過了內存的邊界,所以導致STACK corrupted
a[6] = 'A';
如果把a[6]修改爲a[0],問題就可以解決了。