Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cstdlib>
- #include <iostream>
- #include <string>
- using namespace std;
- void Assert(bool value, const string& hint) {
- if(value == false){
- if(hint.empty()){
- cout << "Assertion failed." << endl;
- abort();
- }
- else{
- cout << "Assertion failed. Hint: " << hint << endl;
- abort();
- }
- }
- }
- int main() {
- const string greeting = "Hello"s;
- // Намеренная ошибка в условии, чтобы показать работу Assert
- Assert(greeting.empty(), "Greeting must be non-empty"s);
- // Следующая строка не должна выполниться, так как Assert аварийно завершит работу программы
- cout << "This line will not be printed"s << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement