Visual C++调试断言失败
Visual C++ Debug Assertion Fail
当我编译程序时,它会说"调试断言失败"
当我点击忽略两次时,我的应用程序就会出现
我该怎么修?
下面是整个代码,以防您想对其进行自我测试。该应用程序的数量随着滚动条向右移动而增加,随着滚动条向左移动而减少。但我的主要问题是调试断言失败了。如果你能发布代码中有问题的部分,以及我如何修复它或修复它并发布代码。有什么方法可以通过使用try-and-catch来消除运行时的错误吗。我的意思是请解决那个问题。这是一个项目,我只有一周半的时间来做。如果你能帮我做这个项目,你的帮助将不胜感激。我对visual c++还相当陌生。部分错误是:
程序E:\BHCCHardwareStore\Debug\bHCHardwareStore.exe FIle:f\dd\vctools\vc7libs\ship\atmfc\src\mfc\appcore.cpp行:196。有关程序如何导致断言失败的信息,请参阅有关断言的Visual C++文档。(按"重试"可调试应用程序)。
现在,当我点击忽略它时,它会显示应用程序非常好。这个应用程序似乎运行得很好。如何修复此错误此代码不是我剪切和粘贴的全部代码?
#include "stdafx.h"
#include <strstream>
#include <afxwin.h>
#include <string.h>
const int IDC_SB1 = 100;
const int IDC_CS1 = 101;
const int IDC_CS2 = 102;
const int IDC_BUTTON = 103;
const int MIN_RANGE = 0;
const int MAX_RANGE = 100;
class CApp :public CWinApp
{
public:
virtual BOOL InitInstance();
};
CApp App;
class CSource :public CFrameWnd
{
CScrollBar*sb1;
CStatic* cs1;
CStatic* cs2;
CButton* button;
public:
CSource();
afx_msg void OnHScroll(UINT nSBCode,
UINT nPos, CScrollBar* pSccrollBar);
afx_msg void handleButton();
DECLARE_MESSAGE_MAP();
};
BEGIN_MESSAGE_MAP(CSource, CFrameWnd)
ON_WM_HSCROLL()
ON_BN_CLICKED(IDC_BUTTON, handleButton)
END_MESSAGE_MAP()
//Window cONSTRUCTOR
CSource::CSource()
{
}
void CSource::OnHScroll(UINT nSBCode,
UINT nPos, CScrollBar* pScrollBar)
{
int pos, dividend = 0, holder = 0, x = 0;
char array[9];
//;
pos = pScrollBar->GetScrollPos();
switch (nSBCode)
{
case SB_LINEUP:
pos -= 1;
break;
case SB_LINEDOWN:
pos += 1;
break;
case SB_PAGEUP:
pos -= 10;
break;
case SB_PAGEDOWN:
pos += 10;
break;
case SB_TOP:
pos = MIN_RANGE;
break;
case SB_BOTTOM:
pos = MAX_RANGE;
break;
case SB_THUMBTRACK:
pos = nPos;
break;
default:
return;
}
if (pos < MIN_RANGE)
pos = MIN_RANGE;
else if (pos > MAX_RANGE)
pos = MAX_RANGE;
sb1->SetScrollPos(pos, TRUE);
//Set the labels to the new values
char s[100];
TCHAR s1[100];
std::ostrstream ostr(s, 100);
ostr << "Decimal Value = " << pos << std::ends;
for (int i = 0; i < 100; i++){
s1[i] = (TCHAR) s[i];
}
SetDlgItemText(IDC_CS1, s1);
ostr.seekp(std::ios::beg);
dividend = pos;
for (int y = 0; y < 9; y++)
array[y] = '0';
int remainder = dividend % 2;
int quotient = dividend / 2;
array[x] = (char)(remainder + 48);
do
{
remainder = quotient % 2;
quotient = quotient / 2;
array[++x] = (char)(remainder + 48);
} while (quotient != 0);
array[8] = ' ';
ostr << "Binary Value = " << _strrev(array) << std::ends;
SetDlgItemText(IDC_CS2, s1);
}
void CSource::handleButton()
{
int result;
result = MessageBox(_T("Are you sure?"), _T("Exiting"),
MB_ICONQUESTION | MB_YESNO);
if (result == IDYES)
{
Beep(1000, 100);
DestroyWindow();
}
else
Beep(200, 100);
}
//Initialize the application and the main window
BOOL CApp::InitInstance()
{
m_pMainWnd = new CSource();
m_pMainWnd->ShowWindow(m_nCmdShow);
m_pMainWnd->UpdateWindow();
return TRUE;
}
您的代码(在VS2013中)在MFC代码中生成断言:
BOOL CWnd::ShowWindow(int nCmdShow)
{
ASSERT(::IsWindow(m_hWnd) || (m_pCtrlSite != NULL));
来自您的电话:
m_pMainWnd->ShowWindow(m_nCmdShow);
您必须先创建窗口,然后才能显示它。
相关文章:
- 尝试使用 std::vector<std::thread时出现静态断言失败错误>
- uint_not_usable_without_attribute在业力规则中使用数字生成器时静态断言失败
- 从 exe 文件 (Visual Studio ) 启动时调试断言失败
- 断言"id < 0"在Qt ActiveX中失败
- 在 CppUnit 中测试中止断言失败
- 使用扫描的调试断言失败
- MS 本机单元测试 - 断言::线程失败不起作用
- 为什么我的Qt程序在断言失败后继续运行?
- 图片不显示,关闭时出错 --> 调试断言失败!表达式:is_block_type_valid(标头>_block_use)
- 访问提升:shared_ptr 主范围外崩溃,断言失败:px != 0.指针的正确用法是什么?
- C++ 调试断言失败 - 矢量下标超出视觉工作室的范围
- 错误:断言失败 (src.type() == CV_8UC1) 在阈值中
- Boost Beast 异步服务器失败,断言失败:(id_ != T::id) 在多个 aync 调用中
- 使用imwrite OpenCV时断言失败
- 调试断言失败的缓冲区!=nullptr
- 使用 ofstream 写入文本文件时断言失败
- OpenCV 错误:相机校准:断言在matrix_wrap.cpp失败
- 提升继续恢复断言失败
- 获取有关调试断言失败的错误:表达式:"(_Ptr_user &(_BIG_ALLOCATION_ALIGNMENT -1)) == 0" &&0
- 打破gdb中失败断言的正确方法是什么