(C++) C++ Builder assert

February 24, 2017 · View on GitHub

 

 

 

 

 

(C++) C++ Builder assert

 

The standard assert does not work nice in C++ Builder when working on a console application. Instead, one can use the code below, which does wait for a key press.

 

 

 

 

 


//--------------------------------------------------------------------------- #ifndef BilderbikkelConsoleAssertH #define BilderbikkelConsoleAssertH //--------------------------------------------------------------------------- //From http://www.richelbilderbeek.nl/CppBuilderAssert.htm #ifdef NDEBUG   #define Assert(x) ((void)0) #else   #include <iostream>   #define Assert(x)                      \   if (! (x))                             \   {                                      \     std::cout                            \       << "ERROR!! Assertion "            \       <<  std::string (#x)               \       <<  " failed\n on line "           \       <<  (__LINE__)                     \       <<  " in the function "            \       <<  (__FUNC__)                     \       <<  "\n in file "                  \       <<  __FILE__                       \       << std::endl;                      \       std::string tempString;            \       std::getline(std::cin,tempString); \   } #endif #endif