Advertisement
kutuzzzov

урок 2

Aug 25th, 2022
446
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.86 KB | None | 0 0
  1. #include <cstdlib>
  2. #include <iostream>
  3. #include <string>
  4.  
  5. using namespace std;
  6.  
  7. void Assert(bool value, const string& hint) {
  8.     // Реализуйте тело функции Assert
  9.     if (value != true) {
  10.         cout << "Assertion failed."s; // значение равно false
  11.         if (!hint.empty()) {
  12.             cout << " Hint: "s << hint;
  13.         }
  14.         cout << endl;
  15.         abort();
  16.     }
  17. }
  18.  
  19. int main() {
  20.     const string greeting = "Hello"s;
  21.     // Намеренная ошибка в условии, чтобы показать работу Assert
  22.     Assert(greeting.empty(), "Greeting must be non-empty"s);
  23.     // Следующая строка не должна выполниться, так как Assert аварийно завершит работу программы
  24.     cout << "This line will not be printed"s << endl;
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement