Someone asked about using the exit function in C when someone types in an invalid expression. You may call exit from anywhere, and it will terminate your whole program. It's just a plain old function that happens to make a call to the operating system telling it to terminate the current program.
However, you should be careful where you use it for design reasons. Suppose you have a class that calls exit whenever something doesn't go right (a file doesn't exist, the arguments are bad, etc.). Then that class can't be used in any other program where you might want to handle an error differently. Suppose you write a GUI and someone tries to open a file that doesn't exist. Suppose you're writing a spreadsheet and the user enters "a=b+" by accident. You don't want the program to terminate, and you also don't want for just an error message to appear on the console (as in cerr << "you goofed").
I suggest you not use exit() or cerr <<, but either:
preturn some value from the function that indicates an error
get really ambitious and try to throw an exception
define an abstract error handler class. Then people who want to use your code can write their own error handlers that fit the situation. (*This solution, as easy as it may seem, involves some more serious design issues and whether or not to use a Singleton...)