/
plato
/
exceptions
Обзор
Документация
Войти
/
plato
/
exceptions
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
ex1/main.cpp
45 строк
1000 B
plato
update ex1/main.cpp
13 окт 2025, 18:31
13 окт 2025, 18:31
3df5770
Код
Авторство
О чём код?
#include <iostream> #include <string> #include <exception> #include <clocale> int function(std::string str, int forbidden_length) { int str_size = str.size(); if (str_size == forbidden_length) throw std::runtime_error("bad_length"); return str_size; } int main () { std::setlocale(LC_ALL, "ru_RU.UTF-8"); int forbidden_length = 0; std::cout << "Введите запретную длину: "; std::cin >> forbidden_length; std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n'); while (true) { std::string str; std::cout << "Введите слово: "; std::getline(std::cin, str); try { int str_len = function(str, forbidden_length); std::cout << "Длина слова \"" << str << "\" равна " << str_len << std::endl; } catch(const std::exception& error) { std::cout << "Вы ввели слово запретной длины! До свидания" << ". Size = " << str.size() << std::endl; return 1; } } return 0; }