调试断言失败!表达式:result_pointer!=nullptr
Posted
技术标签:
【中文标题】调试断言失败!表达式:result_pointer!=nullptr【英文标题】:Debug Assertion Failed! Expression:result_pointer!=nullptr 【发布时间】:2018-03-23 11:21:18 【问题描述】:我正在编写一个 C++ 程序来搜索数组中的给定整数,但是,当我尝试调试程序时,Visual Studio(我使用的是 vs 2015 专业版)抱怨调试断言失败: enter image description here
这是我的代码,非常简单:
int main()
int searchArray[10] = 324,4567,6789,5421345,7,65,8965,12,342,485 ;
//use searchKey for the number to be found
//use location for the array index of the found value
int searchKey, location;
//write code to determine if integers entered by
//the user are in searchArray
//initiate searchKey and location
searchKey = 0;
location = 0;
int n = sizeof(searchArray) / sizeof(searchArray[0]);
//let user define the search key, give -1 to quit
while (true)
std::cout << "Enter an integer ('-1') to quit: ";
scanf_s("%d", searchKey);
std::cout << searchKey << "\n";
if (searchKey == -1)
break;
for (location; location < n; location++)
if (searchArray[location] == searchKey)
break;
location = -1;
if (location != -1)
std::cout << searchKey << " is at location " << location << " in the array.\n";
else
std::cout << searchKey << " is not in the array.\n";
return 0;
【问题讨论】:
您解决了这个问题吗?如果在代码行中的“searchKey”之前添加“&”,结果如何? 【参考方案1】:每个参数都必须是指向一个类型变量的指针,该类型与格式中的类型说明符相对应。
只需将代码 "scanf_s("%d", searchKey)" 更改为:
scanf_s("%d", &searchKey);
它会很好用。
【讨论】:
以上是关于调试断言失败!表达式:result_pointer!=nullptr的主要内容,如果未能解决你的问题,请参考以下文章
调试断言失败表达式:_pFirstBlock == pHead 使用 OpenCV 和 C++ 尝试调用 SurfFeatureDetector
调试断言失败!表达式:_BLOCK_TYPE_IS_VALID(pHead->nBlockUse)