我有這樣的代碼:的Visual Studio檢查迭代器不拋出異常
#ifdef _DEBUG
#define _SECURE_SCL 1
#define _SECURE_SCL_THROWS 1
#else
#define _SECURE_SCL 0
#define _SECURE_SCL_THROWS 0
#endif
#include <iostream>
#include <vector>
using namespace std;
int main()
{
vector <int> v1;
v1.push_back(33);
vector <int>::iterator it1 = v1.begin();
try
{
it1++;
it1++;
}
catch (...)
{
cout << "vector is empty!!" << endl;
}
return 0;
}
一個非常簡單的一個:我試圖晃過-的邊界,我想可以捕捉到的異常。然而,程序只是崩潰與「調試斷言失敗!」在第二個增量上,爲什麼是這樣?
該示例取自http://msdn.microsoft.com/en-us/library/aa985965(v=vs.100).aspx,我剛剛添加了宏以設置選中的迭代器。我在調試模式下,/ EHSC上,所以是/ MDD
我認爲您需要在爲矢量包含標題之前定義這些宏。 –
@NathanMonteleone:他不應該定義這些宏。根據他所鏈接的文章,他應該使用'/ D_DEBUG/EHsc/MDd'編譯 –
如果我在源代碼中定義這些宏,這不就是一樣嗎? –