콘솔을 열지 않고도 새 창에 메시지를 표시하는 Assert 기능을 생성하려고합니다. 이 함수는 독립적이어야하며 가능한 경우 C++ 외부 라이브러리를 사용하지 않아야합니다. GUI 작업을 포함하지 않는 출력에MessageBox OS입니다. Independent
#include <string>
#include <sstream>
#ifdef WIN32
#include <windows.h> // include windows header, for Windows Based Sistems.
#else
// ...
#endif
void Assert (bool cond,const char* file,int line,const char* desc)
{
if (cond) return; // No Assertion.
#ifdef WIN32
// Use MessageBox function to display the information.
// For Example ...
std::stringstream st;
st << "There Was An Error At Runtime ! \n";
st << "File: " << file << "\n";
st << "Line: " << line << "\n";
st << "Description: " << desc << "\n";
st << "Do You Want To Continue Running the Application?\n";
if (MessageBox (NULL,"Unexpected Error", str.str().c_str(), MB_YESNO) == IDNO)
exit (-1);
#else
// Do Something, but in Unix Base Systems.
#endif
}
#define assert(condition,description) \
__assert__ (condition,__FILE__,__LINE__,description)
필요 C++ 코드 다른 O.S
다른 OS를 정의하십시오 - 너무 많습니다 – Zaffy
리눅스, 매킨토시 –
#ifdef WIN32의 #else 뒤에 실제로 코드를 작성하지 않으시겠습니까? 나머지는 훨씬 간단 해지기 때문에 추측 할 필요가 없습니다. –