# Include <iostream> <br/> # include <stdexcept> <br/> # include <cassert> <br/> using namespace STD; <br/> int main (INT argc, char * agrv []) <br/>{< br/> # ifndef ndebug <br/> cerr <"Main start" <Endl <br/> <"line: "<_ line __< <Endl; <br/> # endif <br/> char ch; <br/> while (CIN> CH) <br/>{< br/> assert (Ch! = 'X'); <br/> try <br/>{< br/> If (CH = 'y') <br/> throw runtime_error ("error: shocould not be y "); <br/> cout <" you input correct! You input is: "<ch <Endl; <br/>}< br/> catch (runtime_error ERR) <br/>{< br/> cout <err. what () <Endl <br/> <"Try again? "<Endl; <br/> char C; <br/> CIN> C; <br/> If (CIN & C = 'n ') <br/> break; <br/>}< br/>}
During compilation, you can use: G ++-D ndebug filename. cpp-O filename to specify the macro switch.
Pay special attention to assert, which only plays a role in debugging. The assert statement is ignored for programs compiled in non-debug mode. Therefore, you must never use assert to control your program logic.