<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title>IT Services</title>
		<link>http://it-solutions.ucoz.ru/</link>
		<description>Блог</description>
		<lastBuildDate>Tue, 03 Dec 2013 20:43:43 GMT</lastBuildDate>
		<generator>uCoz Web-Service</generator>
		<atom:link href="https://it-solutions.ucoz.ru/blog/rss" rel="self" type="application/rss+xml" />
		
		<item>
			<title>Генерация псевдослучайных чисел на С и С++</title>
			<description>&lt;span style=&quot;font-size: small; line-height: 22.399999618530273px; font-family: Cambria, serif; border: 1pt none windowtext; padding: 0cm;&quot;&gt;Часто при начальном тестировании программы надоедает &amp;nbsp;вводить разнообразные числа, чтобы проверить минимальную работоспособность программы.&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-size: small; line-height: 22.399999618530273px; font-family: Cambria, serif;&quot;&gt;&lt;br&gt;&lt;span style=&quot;border: 1pt none windowtext; padding: 0cm;&quot;&gt;&lt;span style=&quot;outline: 0px;&quot;&gt;Поэтому для тех, кто не любит заранее приготовлять юнит-тесты (или не знает, что это такое), я расскажу как быстро присваивать своим переменным случайные значения.&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;</description>
			<content:encoded>&lt;p class=&quot;font8&quot; style=&quot;margin:0cm;margin-bottom:.0001pt;line-height:16.8pt;
vertical-align:baseline&quot;&gt;&lt;font size=&quot;2&quot;&gt;&lt;span style=&quot;font-family: Cambria, serif; border: 1pt none windowtext; padding: 0cm;&quot;&gt;Часто при начальном тестировании программы надоедает &amp;nbsp;вводить
разнообразные числа, чтобы проверить минимальную работоспособность программы.&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-family: Cambria, serif;&quot;&gt;&lt;br&gt;
&lt;span style=&quot;border:none windowtext 1.0pt;mso-border-alt:none windowtext 0cm;
padding:0cm&quot;&gt;&lt;span style=&quot;outline: 0px&quot;&gt;Поэтому для тех, кто не любит заранее
приготовлять юнит-тесты (или не знает, что это такое), я расскажу как быстро
присваивать своим переменным случайные значения.&lt;/span&gt;&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/font&gt;&lt;/p&gt;

&lt;p class=&quot;font8&quot; style=&quot;margin: 0cm 0cm 0.0001pt; line-height: 16.8pt; vertical-align: baseline; outline: 0px;&quot;&gt;&lt;span style=&quot;font-family: Cambria, serif;&quot;&gt;&lt;font size=&quot;2&quot;&gt;&amp;nbsp;&lt;o:p&gt;&lt;/o:p&gt;&lt;/font&gt;&lt;/span&gt;&lt;/p&gt;

&lt;p class=&quot;font8&quot; style=&quot;margin: 0cm 0cm 0.0001pt; line-height: 16.8pt; vertical-align: baseline; outline: 0px;&quot;&gt;&lt;font size=&quot;2&quot;&gt;&lt;span style=&quot;outline: 0px&quot;&gt;&lt;span style=&quot;font-family: Cambria, serif; border: 1pt none windowtext; padding: 0cm;&quot;&gt;Из
языка С нам известна функция &lt;span style=&quot;color: rgb(255, 215, 0);&quot;&gt;int rand ( void )&lt;/span&gt; из библиотеки &lt;span style=&quot;color: rgb(255, 215, 0);&quot;&gt;&lt;stdlib&amp;gt;&lt;/span&gt;, которая
генерирует случайное число от 0 до RAD_MAX ( ~ 32767).&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: Cambria, serif;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/font&gt;&lt;/p&gt;

&lt;p class=&quot;font8&quot; style=&quot;margin: 0cm 0cm 0.0001pt; line-height: 16.8pt; vertical-align: baseline; outline: 0px;&quot;&gt;&lt;span style=&quot;font-family: Cambria, serif;&quot;&gt;&lt;font size=&quot;2&quot;&gt;&amp;nbsp;&lt;o:p&gt;&lt;/o:p&gt;&lt;/font&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;font8&quot; style=&quot;margin: 0cm 0cm 0.0001pt; line-height: 16.8pt; vertical-align: baseline; outline: 0px;&quot;&gt;&lt;span style=&quot;font-family: Cambria, serif;&quot;&gt;&lt;font size=&quot;2&quot;&gt;Пусть наше значение&amp;nbsp;&lt;/font&gt;&lt;/span&gt;&lt;span style=&quot;font-size: small; font-family: Cambria, serif; line-height: 16.8pt;&quot;&gt;int value = 0;&lt;/span&gt;&lt;/p&gt;

&lt;p class=&quot;font8&quot; style=&quot;margin: 0cm 0cm 0.0001pt; line-height: 16.8pt; vertical-align: baseline; outline: 0px;&quot;&gt;&lt;span style=&quot;font-family: Cambria, serif;&quot;&gt;&lt;font size=&quot;2&quot;&gt;&amp;nbsp;&lt;o:p&gt;&lt;/o:p&gt;&lt;/font&gt;&lt;/span&gt;&lt;/p&gt;

&lt;p class=&quot;font8&quot; style=&quot;margin: 0cm 0cm 0.0001pt; line-height: 16.8pt; vertical-align: baseline; outline: 0px;&quot;&gt;&lt;font size=&quot;2&quot;&gt;&lt;span style=&quot;outline: 0px&quot;&gt;&lt;span style=&quot;font-family: Cambria, serif; border: 1pt none windowtext; padding: 0cm;&quot;&gt;Что нам нужно сделать, чтобы получить случайное число от 0 до 9? &amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: Cambria, serif;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/font&gt;&lt;/p&gt;

&lt;p class=&quot;font8&quot; style=&quot;margin: 0cm 0cm 0.0001pt; line-height: 16.8pt; vertical-align: baseline; outline: 0px;&quot;&gt;&lt;span style=&quot;font-family: Cambria, serif;&quot;&gt;&lt;font size=&quot;2&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: rgb(255, 215, 0);&quot;&gt;value = rand( ) % 10;&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/font&gt;&lt;/span&gt;&lt;/p&gt;

&lt;p class=&quot;font8&quot; style=&quot;margin: 0cm 0cm 0.0001pt; line-height: 16.8pt; vertical-align: baseline; outline: 0px;&quot;&gt;&lt;span style=&quot;font-family: Cambria, serif;&quot;&gt;&lt;font size=&quot;2&quot;&gt;&amp;nbsp;&lt;o:p&gt;&lt;/o:p&gt;&lt;/font&gt;&lt;/span&gt;&lt;/p&gt;

&lt;p class=&quot;font8&quot; style=&quot;margin: 0cm 0cm 0.0001pt; line-height: 16.8pt; vertical-align: baseline; outline: 0px;&quot;&gt;&lt;span style=&quot;font-family: Cambria, serif;&quot;&gt;&lt;font size=&quot;2&quot;&gt;А если мы хотим от 1 до 9?&lt;o:p&gt;&lt;/o:p&gt;&lt;/font&gt;&lt;/span&gt;&lt;/p&gt;

&lt;p class=&quot;font8&quot; style=&quot;margin: 0cm 0cm 0.0001pt; line-height: 16.8pt; vertical-align: baseline; outline: 0px;&quot;&gt;&lt;span style=&quot;font-family: Cambria, serif;&quot;&gt;&lt;font size=&quot;2&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: rgb(255, 215, 0);&quot;&gt;value = rand( ) % 9 &amp;nbsp;&amp;nbsp;+ 1;&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/font&gt;&lt;/span&gt;&lt;/p&gt;

&lt;p class=&quot;font8&quot; style=&quot;margin: 0cm 0cm 0.0001pt; line-height: 16.8pt; vertical-align: baseline; outline: 0px;&quot;&gt;&lt;span style=&quot;font-family: Cambria, serif;&quot;&gt;&lt;font size=&quot;2&quot;&gt;&amp;nbsp;&lt;o:p&gt;&lt;/o:p&gt;&lt;/font&gt;&lt;/span&gt;&lt;/p&gt;

&lt;p class=&quot;font8&quot; style=&quot;margin: 0cm 0cm 0.0001pt; line-height: 16.8pt; vertical-align: baseline; outline: 0px;&quot;&gt;&lt;span style=&quot;font-family: Cambria, serif;&quot;&gt;&lt;font size=&quot;2&quot;&gt;Функция &lt;span style=&quot;color: rgb(255, 215, 0);&quot;&gt;rand( )&lt;/span&gt; генерирует последовательность значений,
вычисляемую по специальному алгоритму, который зависит от &quot;зерна&quot;
(seed), по умолчанию равного&amp;nbsp;единице.&lt;o:p&gt;&lt;/o:p&gt;&lt;/font&gt;&lt;/span&gt;&lt;/p&gt;

&lt;p class=&quot;font8&quot; style=&quot;margin: 0cm 0cm 0.0001pt; line-height: 16.8pt; vertical-align: baseline; outline: 0px;&quot;&gt;&lt;span style=&quot;font-family: Cambria, serif;&quot;&gt;&lt;font size=&quot;2&quot;&gt;&amp;nbsp; &amp;nbsp;Поэтому последовательность всегда одинакова.&lt;o:p&gt;&lt;/o:p&gt;&lt;/font&gt;&lt;/span&gt;&lt;/p&gt;

&lt;p class=&quot;font8&quot; style=&quot;margin: 0cm 0cm 0.0001pt; line-height: 16.8pt; vertical-align: baseline; outline: 0px;&quot;&gt;&lt;span style=&quot;font-family: Cambria, serif;&quot;&gt;&lt;font size=&quot;2&quot;&gt;&amp;nbsp;&lt;o:p&gt;&lt;/o:p&gt;&lt;/font&gt;&lt;/span&gt;&lt;/p&gt;

&lt;p class=&quot;font8&quot; style=&quot;margin: 0cm 0cm 0.0001pt; line-height: 16.8pt; vertical-align: baseline; outline: 0px;&quot;&gt;&lt;span style=&quot;font-family: Cambria, serif;&quot;&gt;&lt;font size=&quot;2&quot;&gt;А что делать, если нам нужна уникальная последовательность
значений при каждом присваивании?&lt;o:p&gt;&lt;/o:p&gt;&lt;/font&gt;&lt;/span&gt;&lt;/p&gt;

&lt;p class=&quot;font8&quot; style=&quot;margin: 0cm 0cm 0.0001pt; line-height: 16.8pt; vertical-align: baseline; outline: 0px;&quot;&gt;&lt;span style=&quot;font-family: Cambria, serif;&quot;&gt;&lt;font size=&quot;2&quot;&gt;Для этого воспользуемся &lt;span style=&quot;color: rgb(255, 215, 0);&quot;&gt;void srand(unsigned int
seed)&lt;/span&gt;&amp;nbsp;&lt;/font&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;font8&quot; style=&quot;margin: 0cm 0cm 0.0001pt; line-height: 16.8pt; vertical-align: baseline; outline: 0px;&quot;&gt;&lt;span style=&quot;font-family: Cambria, serif;&quot;&gt;&lt;font size=&quot;2&quot;&gt;(эта функция то же из&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: rgb(255, 215, 0);&quot;&gt;&lt;stdlib&amp;gt;&lt;/span&gt; ),&amp;nbsp;которая меняет &quot;зерно&quot;.&lt;o:p&gt;&lt;/o:p&gt;&lt;/font&gt;&lt;/span&gt;&lt;/p&gt;

&lt;p class=&quot;font8&quot; style=&quot;margin: 0cm 0cm 0.0001pt; line-height: 16.8pt; vertical-align: baseline; outline: 0px;&quot;&gt;&lt;span style=&quot;font-family: Cambria, serif;&quot;&gt;&lt;font size=&quot;2&quot;&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: rgb(255, 215, 0);&quot;&gt;&amp;nbsp; srand( 3 ); &amp;nbsp; value_1 =
rand();&amp;nbsp;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/font&gt;&lt;/span&gt;&lt;/p&gt;

&lt;p class=&quot;font8&quot; style=&quot;margin: 0cm 0cm 0.0001pt; line-height: 16.8pt; vertical-align: baseline; outline: 0px;&quot;&gt;&lt;font size=&quot;2&quot;&gt;&lt;span style=&quot;outline: 0px&quot;&gt;&lt;span style=&quot;font-family: Cambria, serif; border: 1pt none windowtext; padding: 0cm;&quot;&gt;&lt;span style=&quot;color: rgb(255, 215, 0);&quot;&gt;&amp;nbsp;
&amp;nbsp; &amp;nbsp; srand( 5&amp;nbsp;); &amp;nbsp; value_2 = rand(); &amp;nbsp;&lt;/span&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/font&gt;&lt;/p&gt;&lt;p class=&quot;font8&quot; style=&quot;margin: 0cm 0cm 0.0001pt; line-height: 16.8pt; vertical-align: baseline; outline: 0px;&quot;&gt;&lt;font size=&quot;2&quot;&gt;&lt;span style=&quot;outline: 0px&quot;&gt;&lt;span style=&quot;font-family: Cambria, serif; border: 1pt none windowtext; padding: 0cm;&quot;&gt;Теперь value_1
&amp;nbsp;не равно&amp;nbsp; value_2.&lt;/span&gt;&lt;/span&gt;&lt;/font&gt;&lt;/p&gt;

&lt;p class=&quot;font8&quot; style=&quot;margin: 0cm 0cm 0.0001pt; line-height: 16.8pt; vertical-align: baseline; outline: 0px;&quot;&gt;&lt;span style=&quot;font-family: Cambria, serif;&quot;&gt;&lt;font size=&quot;2&quot;&gt;&amp;nbsp;&lt;o:p&gt;&lt;/o:p&gt;&lt;/font&gt;&lt;/span&gt;&lt;/p&gt;

&lt;p class=&quot;font8&quot; style=&quot;margin: 0cm 0cm 0.0001pt; line-height: 16.8pt; vertical-align: baseline; outline: 0px;&quot;&gt;&lt;font size=&quot;2&quot;&gt;&lt;span style=&quot;outline: 0px&quot;&gt;&lt;span style=&quot;font-family: Cambria, serif; border: 1pt none windowtext; padding: 0cm;&quot;&gt;Отлично!&amp;nbsp;Теперь
мы можем задавать огромное количество случайных
последовательностей&amp;nbsp;неравных друг другу, просто меняя значения зерна.&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: Cambria, serif;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/font&gt;&lt;/p&gt;

&lt;p class=&quot;font8&quot; style=&quot;margin: 0cm 0cm 0.0001pt; line-height: 16.8pt; vertical-align: baseline; outline: 0px;&quot;&gt;&lt;span style=&quot;font-family: Cambria, serif;&quot;&gt;&lt;font size=&quot;2&quot;&gt;&amp;nbsp;&lt;o:p&gt;&lt;/o:p&gt;&lt;/font&gt;&lt;/span&gt;&lt;/p&gt;

&lt;p class=&quot;font8&quot; style=&quot;margin: 0cm 0cm 0.0001pt; line-height: 16.8pt; vertical-align: baseline; outline: 0px;&quot;&gt;&lt;span style=&quot;font-family: Cambria, serif;&quot;&gt;&lt;font size=&quot;2&quot;&gt;Ну а если я хочу, чтобы при повторном запуске программы все
зёрна изменились?&lt;o:p&gt;&lt;/o:p&gt;&lt;/font&gt;&lt;/span&gt;&lt;/p&gt;

&lt;p class=&quot;font8&quot; style=&quot;margin: 0cm 0cm 0.0001pt; line-height: 16.8pt; vertical-align: baseline; outline: 0px;&quot;&gt;&lt;span style=&quot;font-family: Cambria, serif;&quot;&gt;&lt;font size=&quot;2&quot;&gt;Для этого воспользуемся функцией &lt;span style=&quot;color: rgb(255, 215, 0);&quot;&gt;time_t &amp;nbsp;time (time_t*
timer)&lt;/span&gt;&amp;nbsp;из &lt;span style=&quot;color: rgb(255, 215, 0);&quot;&gt;&lt;ctime&amp;gt;&lt;/span&gt;, которая при вызове с нулевым указателем
возвращает количество секунд прошедших с 1 января 1970 года.&lt;o:p&gt;&lt;/o:p&gt;&lt;/font&gt;&lt;/span&gt;&lt;/p&gt;

&lt;p class=&quot;font8&quot; style=&quot;margin: 0cm 0cm 0.0001pt; line-height: 14.7pt; vertical-align: baseline; outline: 0px; max-width: 99.9000015258789%;&quot;&gt;&lt;span style=&quot;font-family: Cambria, serif;&quot;&gt;&lt;font size=&quot;2&quot;&gt;&amp;nbsp;
&amp;nbsp; &amp;nbsp;&lt;span style=&quot;color: rgb(255, 215, 0);&quot;&gt; srand( &amp;nbsp; time(NULL) &amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;); &amp;nbsp;&amp;nbsp;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/font&gt;&lt;/span&gt;&lt;/p&gt;

&lt;p class=&quot;font8&quot; style=&quot;margin: 0cm 0cm 0.0001pt; line-height: 14.7pt; vertical-align: baseline; outline: 0px; max-width: 99.9000015258789%;&quot;&gt;&lt;span style=&quot;font-family: Cambria, serif;&quot;&gt;&lt;font size=&quot;2&quot;&gt;&lt;span style=&quot;color: rgb(255, 215, 0);&quot;&gt;&amp;nbsp;
&amp;nbsp; &amp;nbsp; value_1 = rand();&lt;/span&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;/* теперь value_1 всегда разное &amp;nbsp;*/&lt;o:p&gt;&lt;/o:p&gt;&lt;/font&gt;&lt;/span&gt;&lt;/p&gt;

&lt;p class=&quot;font8&quot; style=&quot;margin: 0cm 0cm 0.0001pt; line-height: 14.7pt; vertical-align: baseline; outline: 0px; max-width: 99.9000015258789%;&quot;&gt;&lt;span style=&quot;font-family: Cambria, serif;&quot;&gt;&lt;font size=&quot;2&quot;&gt;&amp;nbsp;&lt;/font&gt;&lt;/span&gt;&lt;/p&gt;

&lt;p class=&quot;font8&quot; style=&quot;margin: 0cm 0cm 0.0001pt; line-height: 14.7pt; vertical-align: baseline; outline: 0px; max-width: 99.9000015258789%;&quot;&gt;&lt;span style=&quot;font-family: Cambria, serif;&quot;&gt;&lt;font size=&quot;2&quot;&gt;&amp;nbsp;
&amp;nbsp; &amp;nbsp;&lt;span style=&quot;color: rgb(255, 215, 0);&quot;&gt; srand( &amp;nbsp; time(NULL) + 1); &amp;nbsp;&amp;nbsp;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/font&gt;&lt;/span&gt;&lt;/p&gt;

&lt;p class=&quot;font8&quot; style=&quot;margin: 0cm 0cm 0.0001pt; line-height: 14.7pt; vertical-align: baseline; outline: 0px; max-width: 99.9000015258789%;&quot;&gt;&lt;span style=&quot;font-family: Cambria, serif;&quot;&gt;&lt;font size=&quot;2&quot;&gt;&lt;span style=&quot;color: rgb(255, 215, 0);&quot;&gt;&amp;nbsp;
&amp;nbsp; &amp;nbsp; value_2 = rand();&lt;/span&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; /* &amp;nbsp;и&amp;nbsp;value_1 &amp;nbsp;всегда не равно&amp;nbsp;&amp;nbsp;value_2 */&lt;/font&gt;&lt;/span&gt;&lt;/p&gt;</content:encoded>
			<link>https://it-solutions.ucoz.ru/blog/random_number/2013-12-04-25</link>
			<category>С/C++</category>
			<dc:creator>B@R_LOG</dc:creator>
			<guid>https://it-solutions.ucoz.ru/blog/random_number/2013-12-04-25</guid>
			<pubDate>Tue, 03 Dec 2013 20:43:43 GMT</pubDate>
		</item>
		<item>
			<title>Структуры данных: класс Stack</title>
			<description>&lt;font face=&quot;Cambria, serif&quot;&gt;&lt;span style=&quot;font-size: 16px;&quot;&gt;Что такое Stack&amp;nbsp;и как его реализовать на С++ с помощью шаблонов?&lt;/span&gt;&lt;/font&gt;&lt;br&gt;&lt;font face=&quot;Cambria, serif&quot;&gt;&lt;span style=&quot;font-size: 16px;&quot;&gt;Об этом вы сможете узнать в этой статье.&lt;/span&gt;&lt;/font&gt;</description>
			<content:encoded>&lt;p class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;&lt;span style=&quot;font-size:
12.0pt;font-family:&quot;Cambria&quot;,&quot;serif&quot;;mso-ascii-theme-font:major-latin;
mso-hansi-theme-font:major-latin;mso-bidi-font-family:Tahoma&quot;&gt;Стеком в
программировании называется структура данных, где новый элемент всегда добавляется
в конец массива и он же удаляется (извлекается) первым.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;&lt;span style=&quot;font-size:
12.0pt;font-family:&quot;Cambria&quot;,&quot;serif&quot;;mso-ascii-theme-font:major-latin;
mso-hansi-theme-font:major-latin;mso-bidi-font-family:Tahoma&quot;&gt;Логика стека
хорошо характеризуется с помощью термина FILO (&quot; последним пришёл, первым
ушёл&quot; ). &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;&lt;span style=&quot;font-size:
12.0pt;font-family:&quot;Cambria&quot;,&quot;serif&quot;;mso-ascii-theme-font:major-latin;
mso-hansi-theme-font:major-latin;mso-bidi-font-family:Tahoma&quot;&gt;Таким образом
самый первый элемент будет извлечён из стека самым последним.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;&lt;span style=&quot;font-size:
12.0pt;font-family:&quot;Cambria&quot;,&quot;serif&quot;;mso-ascii-theme-font:major-latin;
mso-hansi-theme-font:major-latin;mso-bidi-font-family:Tahoma&quot;&gt;Стек имеет свои
ограничения: &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;&lt;span style=&quot;font-size:
12.0pt;font-family:&quot;Cambria&quot;,&quot;serif&quot;;mso-ascii-theme-font:major-latin;
mso-hansi-theme-font:major-latin;mso-bidi-font-family:Tahoma&quot;&gt;1. Максимальный
размер стека определяется изначально неким числом max_size. В течение
существования объекта класса количество его элементов не может быть больше этого
max_size.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;&lt;span style=&quot;font-size:
12.0pt;font-family:&quot;Cambria&quot;,&quot;serif&quot;;mso-ascii-theme-font:major-latin;
mso-hansi-theme-font:major-latin;mso-bidi-font-family:Tahoma&quot;&gt;2. Нельзя удалить
элемент, если его нет. Поэтому перед удалением всегда надо проверять стек на
наличие минимум одного элемента.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;&lt;span style=&quot;font-size:
12.0pt;font-family:&quot;Cambria&quot;,&quot;serif&quot;;mso-ascii-theme-font:major-latin;
mso-hansi-theme-font:major-latin;mso-bidi-font-family:Tahoma&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;&lt;span style=&quot;font-size:
12.0pt;font-family:&quot;Cambria&quot;,&quot;serif&quot;;mso-ascii-theme-font:major-latin;
mso-hansi-theme-font:major-latin;mso-bidi-font-family:Tahoma&quot;&gt;&amp;nbsp;Ниже приведена реализация класса Stack с
помощью шаблонов. Скачать исходники можно по ссылке ниже.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;&lt;span style=&quot;font-size:
12.0pt;font-family:&quot;Cambria&quot;,&quot;serif&quot;;mso-ascii-theme-font:major-latin;
mso-hansi-theme-font:major-latin;mso-bidi-font-family:Tahoma&quot;&gt;&lt;a href=&quot;http://it-solutions.ucoz.ru/load/it/code_in_cpp/class_stack/10-1-0-5&quot; target=&quot;Stack&quot; title=&quot;Stack&quot;&gt;Скачать&lt;/a&gt;&lt;br&gt;&lt;/span&gt;&lt;/p&gt;</content:encoded>
			<link>https://it-solutions.ucoz.ru/blog/class_stack/2013-12-02-24</link>
			<category>С/C++</category>
			<dc:creator>B@R_LOG</dc:creator>
			<guid>https://it-solutions.ucoz.ru/blog/class_stack/2013-12-02-24</guid>
			<pubDate>Mon, 02 Dec 2013 19:55:46 GMT</pubDate>
		</item>
		<item>
			<title>Структуры данных: класс &quot;Очередь&quot;</title>
			<description>&lt;font face=&quot;Cambria, serif&quot;&gt;&lt;span style=&quot;font-size: 14pt;&quot;&gt;Что такое очередь и как реализовать её на С++ с помощью шаблонов?&lt;/span&gt;&lt;/font&gt;</description>
			<content:encoded>&lt;p class=&quot;MsoNormal&quot; style=&quot;font-size: 19px; margin-bottom: 0.0001pt;&quot;&gt;&lt;span style=&quot;font-size: 12pt; font-family: Cambria, serif;&quot;&gt;Очередью в программировании называется структура данных, где &amp;nbsp;новый элемент всегда добавляется в конец массива, а удаляется (извлекается) всегда первый.&lt;/span&gt;&lt;span style=&quot;font-size: 8pt; font-family: Cambria, serif;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot; style=&quot;font-size: 19px; margin-bottom: 0.0001pt;&quot;&gt;&lt;span style=&quot;font-size: 12pt; font-family: Cambria, serif;&quot;&gt;&amp;nbsp;FIFO ( First In, First Out - Первым прибыл, первым вышел) - сокращённое название очереди как алгоритма.&lt;/span&gt;&lt;span style=&quot;font-size: 8pt; font-family: Cambria, serif;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot; style=&quot;font-size: 19px; margin-bottom: 0.0001pt;&quot;&gt;&lt;span style=&quot;font-size: 12pt; font-family: Cambria, serif;&quot;&gt;&amp;nbsp;Очередь имеет свои ограничения:&lt;/span&gt;&lt;span style=&quot;font-size: 8pt; font-family: Cambria, serif;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot; style=&quot;font-size: 19px; margin-bottom: 0.0001pt;&quot;&gt;&lt;span style=&quot;font-size: 12pt; font-family: Cambria, serif;&quot;&gt;1. Максимальный размер очереди определяется изначально неким числом max_size. В течение существования объекта класса количество его элементов не может быть больше этого max_size.&lt;/span&gt;&lt;span style=&quot;font-size: 8pt; font-family: Cambria, serif;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot; style=&quot;font-size: 19px; margin-bottom: 0.0001pt;&quot;&gt;&lt;span style=&quot;font-size: 12pt; font-family: Cambria, serif;&quot;&gt;2. Нельзя удалить элемент, если его нет. Поэтому перед удалением всегда надо проверять, &amp;nbsp;очередь на наличие минимум одного элемента.&lt;/span&gt;&lt;span style=&quot;font-size: 8pt; font-family: Cambria, serif;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot; style=&quot;font-size: 19px; margin-bottom: 0.0001pt;&quot;&gt;&lt;span style=&quot;font-size: 12pt; font-family: Cambria, serif;&quot;&gt;3. Допустим есть массив из &quot;4&quot; элементов. Извлечём элемент. Получим что слева есть пустое место, но при этом добавить элемент справа напрямую мы не можем. То есть при max_size=4, очередь может содержать только три элемента ( а после повторного извлечения &amp;nbsp;вообще только два).&lt;/span&gt;&lt;span style=&quot;font-size: 8pt; font-family: Cambria, serif;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot; style=&quot;font-size: 19px; margin-bottom: 0.0001pt;&quot;&gt;&lt;span style=&quot;font-size: 12pt; font-family: Cambria, serif;&quot;&gt;Самым простым способом будет просто переместить после извлечения все элементы массива на одну ячейку влево. Причём это точно всегда будет работать. Но если у нас массив будет не из &quot;4&quot; элементов, а из 1 000 000, то от извлечения 50 000 элементов будет сильная потеря производительности, так как при каждый из 50 000 извлечений мы перемещаем примерно по 1 000 000 элементов массива.&lt;/span&gt;&lt;span style=&quot;font-size: 8pt; font-family: Cambria, serif;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot; style=&quot;font-size: 19px; margin-bottom: 0.0001pt;&quot;&gt;&lt;span style=&quot;font-size: 12pt; font-family: Cambria, serif;&quot;&gt;Рассмотрим теперь алгоритм получше.&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-size: 8pt; font-family: Cambria, serif;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot; style=&quot;font-size: 19px; margin-bottom: 0.0001pt;&quot;&gt;&lt;span style=&quot;font-size: 12pt; font-family: Cambria, serif;&quot;&gt;Представим нашу очередь в виде замкнутого круга. Тогда, немного поигравшись с индексами, можем обойтись без перестановок элементов.&lt;/span&gt;&lt;span style=&quot;font-size: 8pt; font-family: Cambria, serif;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot; style=&quot;font-size: 19px; margin-bottom: 0.0001pt;&quot;&gt;&lt;span style=&quot;font-size: 12pt; font-family: Cambria, serif;&quot;&gt;Как именно это выглядит? Представим очередь в магазин, в которой не очередь перемещается к продавцу ( дружно шагая всем составом), а продавец к очереди: то есть позиция начала очереди постоянно изменяясь стремится к концу очереди.&lt;/span&gt;&lt;span style=&quot;font-size: 8pt; font-family: Cambria, serif;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot; style=&quot;font-size: 19px; margin-bottom: 0.0001pt;&quot;&gt;&lt;span style=&quot;font-size: 12pt; font-family: Cambria, serif;&quot;&gt;В таком случае следить нужно будет не только за концом очереди, но и за её началом. Как организовать круговую работу очереди?&lt;/span&gt;&lt;span style=&quot;font-size: 8pt; font-family: Cambria, serif;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot; style=&quot;font-size: 19px; margin-bottom: 0.0001pt;&quot;&gt;&lt;span style=&quot;font-size: 12pt; font-family: Cambria, serif;&quot;&gt;Когда мы добавляем или извлекаем элементы, то очередь движется вправо. Слева же от начала очереди остаются ненужные ячейки массива, которые и нужно заполнять при вставке новыми элементами, если справа уже дошли до конца массива.&lt;/span&gt;&lt;span style=&quot;font-size: 8pt; font-family: Cambria, serif;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot; style=&quot;font-size: 19px; margin-bottom: 0.0001pt;&quot;&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot; style=&quot;font-size: 19px; margin-bottom: 0.0001pt;&quot;&gt;&lt;span style=&quot;font-size: 12pt; font-family: Cambria, serif;&quot;&gt;&amp;nbsp;Ниже приведена сложная реализация класса Queue с помощью шаблонов. Скачать исходники можно по ссылке ниже.&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot; style=&quot;font-size: 19px; margin-bottom: 0.0001pt;&quot;&gt;&lt;span style=&quot;font-size: 12pt; font-family: Cambria, serif;&quot;&gt;&lt;a href=&quot;http://it-solutions.ucoz.ru/load/it/code_in_cpp/class_queue/10-1-0-4&quot; target=&quot;_blank&quot; title=&quot;Скачать класс &quot;очередь&quot; &quot;&gt;http://it-solutions.ucoz.ru/load/it/code_in_cpp/class_queue/10-1-0-4&lt;/a&gt;&lt;br&gt;&lt;/span&gt;&lt;/p&gt;</content:encoded>
			<link>https://it-solutions.ucoz.ru/blog/class_queue/2013-12-02-23</link>
			<category>С/C++</category>
			<dc:creator>B@R_LOG</dc:creator>
			<guid>https://it-solutions.ucoz.ru/blog/class_queue/2013-12-02-23</guid>
			<pubDate>Mon, 02 Dec 2013 15:49:51 GMT</pubDate>
		</item>
		<item>
			<title>Класс обыкновенных дробей Fraction</title>
			<description>&lt;font face=&quot;Cambria, serif&quot;&gt;&lt;span style=&quot;font-size: 14pt;&quot;&gt;В этой теме вы узнаете как реализовать класс обыкновенных дробей с помощью языка С++ и объектно-ориентированного программирования.&lt;/span&gt;&lt;/font&gt;</description>
			<content:encoded>&lt;p class=&quot;font_8&quot; style=&quot;margin: 0px; padding: 0px; border: 0px; outline: 0px; vertical-align: baseline; font-size: 14px; line-height: 1.4em; font-family: &apos;open sans&apos;, sans-serif;&quot;&gt;&lt;span style=&quot;margin: 0px; padding: 0px; border: 0px; outline: 0px; vertical-align: baseline; line-height: 1.4em; font-size: 14pt;&quot;&gt;Часто студентам дают задание реализовать класс обыкновенных дробей Fraction на языке С++ с помощью ООП.&amp;nbsp;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;font_8&quot; style=&quot;margin: 0px; padding: 0px; border: 0px; outline: 0px; vertical-align: baseline; font-size: 14px; line-height: 19.59375px; font-family: &apos;open sans&apos;, sans-serif; max-width: 99.9000015258789%;&quot;&gt;&amp;nbsp;&lt;/p&gt;&lt;p class=&quot;font_8&quot; style=&quot;margin: 0px; padding: 0px; border: 0px; outline: 0px; vertical-align: baseline; line-height: 19.59375px; font-family: &apos;open sans&apos;, sans-serif; max-width: 99.9000015258789%;&quot;&gt;&lt;font size=&quot;4&quot; style=&quot;font-size: 14pt;&quot;&gt;Поэтому сегодня я покажу как должно выглядеть решение этой задачи.&lt;/font&gt;&lt;/p&gt;&lt;p class=&quot;font_8&quot; style=&quot;margin: 0px; padding: 0px; border: 0px; outline: 0px; vertical-align: baseline; font-size: 14px; line-height: 19.59375px; font-family: &apos;open sans&apos;, sans-serif; max-width: 99.9000015258789%;&quot;&gt;&amp;nbsp;&lt;/p&gt;&lt;div&gt;&lt;span style=&quot;font-size: 14pt;&quot;&gt;Пример выполнения программы:&amp;nbsp;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: center;&quot;&gt;&lt;span style=&quot;font-size: 10pt;&quot;&gt;&lt;img src=&quot;http://it-solutions.ucoz.ru/10.jpg&quot; alt=&quot;&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;p class=&quot;font_8&quot; style=&quot;margin: 0px; padding: 0px; border: 0px; outline: 0px; vertical-align: baseline; font-size: 14px; line-height: 19.59375px; font-family: &apos;open sans&apos;, sans-serif; max-width: 99.9000015258789%;&quot;&gt;&lt;span style=&quot;font-size: 10pt; font-family: Verdana, Tahoma, Arial;&quot;&gt;&lt;br&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;font_8&quot; style=&quot;margin: 0px; padding: 0px; border: 0px; outline: 0px; vertical-align: baseline; font-size: 14px; line-height: 19.59375px; font-family: &apos;open sans&apos;, sans-serif; max-width: 99.9000015258789%;&quot;&gt;&lt;span style=&quot;font-size: 14pt; font-family: Verdana, Tahoma, Arial;&quot;&gt;Мой преподаватель не нашёл данных и операций, с которыми этот класс не работает, но небольшой сюрприз я решил вам оставить:&amp;nbsp;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;font_8&quot; style=&quot;margin: 0px; padding: 0px; border: 0px; outline: 0px; vertical-align: baseline; font-size: 14px; line-height: 19.59375px; font-family: &apos;open sans&apos;, sans-serif; max-width: 99.9000015258789%;&quot;&gt;&lt;span style=&quot;font-size: 10pt; font-family: Verdana, Tahoma, Arial;&quot;&gt;&lt;br&gt;&lt;/span&gt;&lt;/p&gt;&lt;blockquote style=&quot;margin: 0 0 0 40px; border: none; padding: 0px;&quot;&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;img src=&quot;http://it-solutions.ucoz.ru/11.jpg&quot; alt=&quot;&quot; style=&quot;font-size: small; text-align: center;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/blockquote&gt;&lt;div style=&quot;text-align: right;&quot;&gt;&lt;br&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;font-size: 14pt;&quot;&gt;В этой функции уже при x=24 у вас будет неправильный результат.&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-size: 14pt;&quot;&gt;Почему?&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;font-size: 10pt;&quot;&gt;&lt;br&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;font-size: 14pt;&quot;&gt;Потому что в результате переполнения вы получаете неправильные данные.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;font-size: 10pt;&quot;&gt;&lt;br&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;font-size: 14pt;&quot;&gt;double_max = 9 223 372 036 854 775 807 &amp;nbsp;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;font-size: 14pt;&quot;&gt;int_max = 2 147 483 647&lt;br&gt;&lt;br&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;font-size: 14pt;&quot;&gt;Везде по разному, но различие в порядках значений очевидно.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;font-size: 14pt;&quot;&gt;Поэтому в строчке 29, если выражение (value_1 - value_2) не умещается в int, то получим переполнение -&amp;gt; неправильный числитель.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;font-size: 10pt;&quot;&gt;&lt;br&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;font-size: 14pt;&quot;&gt;Наилучшим решением будет переписать алгоритм так, чтобы он, в зависимости от &quot;x&quot;, умножал на 10 в нужной степени, а не с запасом, как здесь.&amp;nbsp;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;br&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;font-size: 14pt;&quot;&gt;Блок CONTROL_INPUT описан&amp;nbsp;&lt;/span&gt;&lt;font size=&quot;4&quot;&gt;&lt;a href=&quot;http://it-solutions.ucoz.ru/blog/control_input/2013-11-18-2&quot; title=&quot;Контроль ввода в C и C++&quot; style=&quot;font-size: 14pt;&quot;&gt;здесь&lt;/a&gt;.&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;br&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;font-size: 14pt;&quot;&gt;Остальное всё просто, поэтому если возникнут вопросы - пишите их в комментарии.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;br&gt;&lt;/div&gt;&lt;div&gt;&lt;font size=&quot;4&quot;&gt;&lt;a href=&quot;http://it-solutions.ucoz.ru/load/it/code_in_cpp/class_fraction/10-1-0-2&quot; style=&quot;font-size: 14pt;&quot;&gt;Скачать&lt;/a&gt;&lt;/font&gt;&lt;/div&gt;</content:encoded>
			<link>https://it-solutions.ucoz.ru/blog/class_fraction/2013-11-19-16</link>
			<category>С/C++</category>
			<dc:creator>B@R_LOG</dc:creator>
			<guid>https://it-solutions.ucoz.ru/blog/class_fraction/2013-11-19-16</guid>
			<pubDate>Tue, 19 Nov 2013 06:56:46 GMT</pubDate>
		</item>
		<item>
			<title>Преобразования типа в C++:</title>
			<description>&lt;span style=&quot;font-family: &apos;open sans&apos;, sans-serif; font-size: 14px; line-height: 19.600000381469727px;&quot;&gt;Неявные преобразования&amp;nbsp;типов часто приводят к ошибкам, которые не всегда легко заметить &amp;nbsp;и быстро обнаружить.&lt;br&gt;Поэтому сегодня я расскажу о том, как с помощью операторов const_cast, static_cast, reintepret_cast и dynamic_cast можно более строго формулировать свои мысли.&lt;/span&gt;</description>
			<content:encoded>&lt;p class=&quot;font_8&quot; style=&quot;margin: 0px; padding: 0px; border: 0px; outline: 0px; vertical-align: baseline; font-size: 14px; line-height: 1.4em; font-family: &apos;open sans&apos;, sans-serif;&quot;&gt;&lt;span style=&quot;margin: 0px; padding: 0px; border: 0px; outline: 0px; vertical-align: baseline; line-height: 1.4em;&quot;&gt;Неявные преобразования&amp;nbsp;типов часто приводят к ошибкам, которые не всегда легко заметить &amp;nbsp;и быстро обнаружить.&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;font_8&quot; style=&quot;margin: 0px; padding: 0px; border: 0px; outline: 0px; vertical-align: baseline; font-size: 14px; line-height: 19.59375px; font-family: &apos;open sans&apos;, sans-serif; max-width: 99.9000015258789%;&quot;&gt;&amp;nbsp;&lt;/p&gt;&lt;p class=&quot;font_8&quot; style=&quot;margin: 0px; padding: 0px; border: 0px; outline: 0px; vertical-align: baseline; font-size: 14px; line-height: 19.59375px; font-family: &apos;open sans&apos;, sans-serif; max-width: 99.9000015258789%;&quot;&gt;Поэтому сегодня я расскажу о новых операторах приведения, которые позволяют более строго оформлять свои мысли и чётче их формулировать.&lt;/p&gt;&lt;p class=&quot;font_8&quot; style=&quot;margin: 0px; padding: 0px; border: 0px; outline: 0px; vertical-align: baseline; font-size: 14px; line-height: 19.59375px; font-family: &apos;open sans&apos;, sans-serif; max-width: 99.9000015258789%;&quot;&gt;&amp;nbsp;&lt;/p&gt;&lt;p class=&quot;font_8&quot; style=&quot;margin: 0px; padding: 0px; border: 0px; outline: 0px; vertical-align: baseline; font-size: 14px; line-height: 19.59375px; font-family: &apos;open sans&apos;, sans-serif; max-width: 99.9000015258789%;&quot;&gt;&lt;span class=&quot;color_23&quot; style=&quot;margin: 0px; padding: 0px; border: 0px; outline: 0px; vertical-align: baseline;&quot;&gt;/*********************************************************************************************&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;font_8&quot; style=&quot;margin: 0px; padding: 0px; border: 0px; outline: 0px; vertical-align: baseline; font-size: 14px; line-height: 19.59375px; font-family: &apos;open sans&apos;, sans-serif; max-width: 99.9000015258789%;&quot;&gt;&lt;span class=&quot;color_23&quot; style=&quot;margin: 0px; padding: 0px; border: 0px; outline: 0px; vertical-align: baseline;&quot;&gt;**********************************************************************************************&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;font_8&quot; style=&quot;margin: 0px; padding: 0px; border: 0px; outline: 0px; vertical-align: baseline; font-size: 14px; line-height: 19.59375px; font-family: &apos;open sans&apos;, sans-serif; max-width: 99.9000015258789%;&quot;&gt;&lt;span class=&quot;color_23&quot; style=&quot;margin: 0px; padding: 0px; border: 0px; outline: 0px; vertical-align: baseline;&quot;&gt;*********************************************************************************************/&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;font_8&quot; style=&quot;margin: 0px; padding: 0px; border: 0px; outline: 0px; vertical-align: baseline; font-size: 14px; line-height: 19.59375px; font-family: &apos;open sans&apos;, sans-serif; max-width: 99.9000015258789%;&quot;&gt;&lt;span style=&quot;margin: 0px; padding: 0px; border: 0px; outline: 0px; vertical-align: baseline; line-height: 1.4em; font-weight: bold;&quot;&gt;Первый:&lt;/span&gt;&lt;span style=&quot;margin: 0px; padding: 0px; border: 0px; outline: 0px; vertical-align: baseline; line-height: 1.4em;&quot;&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;margin: 0px; padding: 0px; border: 0px; outline: 0px; vertical-align: baseline; line-height: 1.4em;&quot;&gt;const_cast &lt; type&amp;nbsp;&amp;gt; ( return_value&amp;nbsp;)&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;font_8&quot; style=&quot;margin: 0px; padding: 0px; border: 0px; outline: 0px; vertical-align: baseline; font-size: 14px; line-height: 19.59375px; font-family: &apos;open sans&apos;, sans-serif; max-width: 99.9000015258789%;&quot;&gt;&lt;span style=&quot;margin: 0px; padding: 0px; border: 0px; outline: 0px; vertical-align: baseline; line-height: 1.4em;&quot;&gt;/*&amp;nbsp;&lt;span style=&quot;margin: 0px; padding: 0px; border: 0px; outline: 0px; vertical-align: baseline; font-style: italic;&quot;&gt;Позволяет добавлять или удалять квалификаторы типов &quot;const&quot; и &quot;volatile&quot; из типов выражения.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;font_8&quot; style=&quot;margin: 0px; padding: 0px; border: 0px; outline: 0px; vertical-align: baseline; font-size: 14px; line-height: 19.59375px; font-family: &apos;open sans&apos;, sans-serif; max-width: 99.9000015258789%;&quot;&gt;&lt;span style=&quot;margin: 0px; padding: 0px; border: 0px; outline: 0px; vertical-align: baseline; line-height: 1.4em;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; const Person* &amp;nbsp;getName() &amp;nbsp; {&amp;nbsp;&lt;span style=&quot;margin: 0px; padding: 0px; border: 0px; outline: 0px; vertical-align: baseline; font-style: italic;&quot;&gt;&amp;nbsp;/* тело функции */&lt;/span&gt;&amp;nbsp;} &amp;nbsp;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;font_8&quot; style=&quot;margin: 0px; padding: 0px; border: 0px; outline: 0px; vertical-align: baseline; font-size: 14px; line-height: 19.59375px; font-family: &apos;open sans&apos;, sans-serif; max-width: 99.9000015258789%;&quot;&gt;&lt;span style=&quot;margin: 0px; padding: 0px; border: 0px; outline: 0px; vertical-align: baseline; line-height: 1.4em;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; Person* &amp;nbsp;anName = const_cast &lt; Person*&amp;nbsp;&amp;gt; ( &amp;nbsp; getName() &amp;nbsp; );&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;font_8&quot; style=&quot;margin: 0px; padding: 0px; border: 0px; outline: 0px; vertical-align: baseline; font-size: 14px; line-height: 19.59375px; font-family: &apos;open sans&apos;, sans-serif; max-width: 99.9000015258789%;&quot;&gt;&lt;span style=&quot;margin: 0px; padding: 0px; border: 0px; outline: 0px; vertical-align: baseline; font-style: italic;&quot;&gt;&lt;span style=&quot;margin: 0px; padding: 0px; border: 0px; outline: 0px; vertical-align: baseline; line-height: 1.4em;&quot;&gt;/* &quot;const_cast&quot; аннулировал &quot;const&quot; в типе значения, возвращаемого функцией getName() */&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;font_8&quot; style=&quot;margin: 0px; padding: 0px; border: 0px; outline: 0px; vertical-align: baseline; font-size: 14px; line-height: 19.59375px; font-family: &apos;open sans&apos;, sans-serif; max-width: 99.9000015258789%;&quot;&gt;&amp;nbsp;&lt;/p&gt;&lt;p class=&quot;font_8&quot; style=&quot;margin: 0px; padding: 0px; border: 0px; outline: 0px; vertical-align: baseline; font-size: 14px; line-height: 19.59375px; font-family: &apos;open sans&apos;, sans-serif; max-width: 99.9000015258789%;&quot;&gt;Эквивалентно худшему варианту:&amp;nbsp;&lt;/p&gt;&lt;p class=&quot;font_8&quot; style=&quot;margin: 0px; padding: 0px; border: 0px; outline: 0px; vertical-align: baseline; font-size: 14px; line-height: 19.59375px; font-family: &apos;open sans&apos;, sans-serif; max-width: 99.9000015258789%;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;anName = ( Person* ) getName();&lt;/p&gt;&lt;p class=&quot;font_8&quot; style=&quot;margin: 0px; padding: 0px; border: 0px; outline: 0px; vertical-align: baseline; font-size: 14px; line-height: 19.59375px; font-family: &apos;open sans&apos;, sans-serif; max-width: 99.9000015258789%;&quot;&gt;&amp;nbsp;&lt;/p&gt;&lt;p class=&quot;font_8&quot; style=&quot;margin: 0px; padding: 0px; border: 0px; outline: 0px; vertical-align: baseline; font-size: 14px; line-height: 19.59375px; font-family: &apos;open sans&apos;, sans-serif; max-width: 99.9000015258789%;&quot;&gt;&lt;span style=&quot;margin: 0px; padding: 0px; border: 0px; outline: 0px; vertical-align: baseline; font-weight: bold;&quot;&gt;Плюсы &quot;const_cast&quot;:&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;font_8&quot; style=&quot;margin: 0px; padding: 0px; border: 0px; outline: 0px; vertical-align: baseline; font-size: 14px; line-height: 19.59375px; font-family: &apos;open sans&apos;, sans-serif; max-width: 99.9000015258789%;&quot;&gt;&amp;nbsp; &amp;nbsp;1) Он бросается в глаза, поэтому видно, что было преобразование типа.&lt;/p&gt;&lt;p class=&quot;font_8&quot; style=&quot;margin: 0px; padding: 0px; border: 0px; outline: 0px; vertical-align: baseline; font-size: 14px; line-height: 19.59375px; font-family: &apos;open sans&apos;, sans-serif; max-width: 99.9000015258789%;&quot;&gt;&amp;nbsp; &amp;nbsp;2) Если будет изменение функции getName из&amp;nbsp;&lt;span style=&quot;margin: 0px; padding: 0px; border: 0px; outline: 0px; vertical-align: baseline; font-weight: bold;&quot;&gt;const Person*&lt;/span&gt;&amp;nbsp;getName() в&lt;span style=&quot;margin: 0px; padding: 0px; border: 0px; outline: 0px; vertical-align: baseline; font-weight: bold;&quot;&gt;&amp;nbsp;const Name*&lt;/span&gt;&amp;nbsp;getName(), то &amp;nbsp; &amp;nbsp; компилятор сообщит об этом, так как возможности &quot;const_cast&quot; ограничены.&lt;/p&gt;&lt;p class=&quot;font_8&quot; style=&quot;margin: 0px; padding: 0px; border: 0px; outline: 0px; vertical-align: baseline; font-size: 14px; line-height: 19.59375px; font-family: &apos;open sans&apos;, sans-serif; max-width: 99.9000015258789%;&quot;&gt;&amp;nbsp;&lt;/p&gt;&lt;p class=&quot;font_8&quot; style=&quot;margin: 0px; padding: 0px; border: 0px; outline: 0px; vertical-align: baseline; font-size: 14px; line-height: 19.59375px; font-family: &apos;open sans&apos;, sans-serif; max-width: 99.9000015258789%;&quot;&gt;&lt;span class=&quot;color_23&quot; style=&quot;margin: 0px; padding: 0px; border: 0px; outline: 0px; vertical-align: baseline;&quot;&gt;/*********************************************************************************************&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;font_8&quot; style=&quot;margin: 0px; padding: 0px; border: 0px; outline: 0px; vertical-align: baseline; font-size: 14px; line-height: 19.59375px; font-family: &apos;open sans&apos;, sans-serif; max-width: 99.9000015258789%;&quot;&gt;&lt;span class=&quot;color_23&quot; style=&quot;margin: 0px; padding: 0px; border: 0px; outline: 0px; vertical-align: baseline;&quot;&gt;**********************************************************************************************&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;font_8&quot; style=&quot;margin: 0px; padding: 0px; border: 0px; outline: 0px; vertical-align: baseline; font-size: 14px; line-height: 19.59375px; font-family: &apos;open sans&apos;, sans-serif; max-width: 99.9000015258789%;&quot;&gt;&lt;span class=&quot;color_23&quot; style=&quot;margin: 0px; padding: 0px; border: 0px; outline: 0px; vertical-align: baseline;&quot;&gt;*********************************************************************************************/&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;font_8&quot; style=&quot;margin: 0px; padding: 0px; border: 0px; outline: 0px; vertical-align: baseline; font-size: 14px; line-height: 19.59375px; font-family: &apos;open sans&apos;, sans-serif; max-width: 99.9000015258789%;&quot;&gt;&lt;span style=&quot;margin: 0px; padding: 0px; border: 0px; outline: 0px; vertical-align: baseline; font-weight: bold;&quot;&gt;Второй:&lt;/span&gt;&amp;nbsp;static_cast &lt; type &amp;gt; ( return_value )&lt;/p&gt;&lt;p class=&quot;font_8&quot; style=&quot;margin: 0px; padding: 0px; border: 0px; outline: 0px; vertical-align: baseline; font-size: 14px; line-height: 19.59375px; font-family: &apos;open sans&apos;, sans-serif; max-width: 99.9000015258789%;&quot;&gt;&lt;span style=&quot;margin: 0px; padding: 0px; border: 0px; outline: 0px; vertical-align: baseline; font-style: italic;&quot;&gt;/* Применяется для переносимых на разные платформы приведений. Чаще всего служит для приведения &quot;вниз&quot; по иерархии наследования от указателя (или ссылки) на базовый класс к указателю (или ссылке) на производный класс. */&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;font_8&quot; style=&quot;margin: 0px; padding: 0px; border: 0px; outline: 0px; vertical-align: baseline; font-size: 14px; line-height: 19.59375px; font-family: &apos;open sans&apos;, sans-serif; max-width: 99.9000015258789%;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;Shape* sp = new Circle;&lt;/p&gt;&lt;p class=&quot;font_8&quot; style=&quot;margin: 0px; padding: 0px; border: 0px; outline: 0px; vertical-align: baseline; font-size: 14px; line-height: 19.59375px; font-family: &apos;open sans&apos;, sans-serif; max-width: 99.9000015258789%;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;Circle* &amp;nbsp;cp = static_cast &lt; Circle* &amp;gt; ( sp );&amp;nbsp;&lt;/p&gt;&lt;p class=&quot;font_8&quot; style=&quot;margin: 0px; padding: 0px; border: 0px; outline: 0px; vertical-align: baseline; font-size: 14px; line-height: 19.59375px; font-family: &apos;open sans&apos;, sans-serif; max-width: 99.9000015258789%;&quot;&gt;&lt;span style=&quot;margin: 0px; padding: 0px; border: 0px; outline: 0px; vertical-align: baseline; font-style: italic;&quot;&gt;&lt;span style=&quot;margin: 0px; padding: 0px; border: 0px; outline: 0px; vertical-align: baseline; line-height: 1.4em;&quot;&gt;/* Компилируется, потому что &quot;&lt;span style=&quot;margin: 0px; padding: 0px; border: 0px; outline: 0px; vertical-align: baseline; font-weight: bold;&quot;&gt;sp&lt;/span&gt;&quot; действительно ссылается на объект &quot;&lt;span style=&quot;margin: 0px; padding: 0px; border: 0px; outline: 0px; vertical-align: baseline; font-weight: bold;&quot;&gt;Circle&lt;/span&gt;&quot;.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;font_8&quot; style=&quot;margin: 0px; padding: 0px; border: 0px; outline: 0px; vertical-align: baseline; font-size: 14px; line-height: 19.59375px; font-family: &apos;open sans&apos;, sans-serif; max-width: 99.9000015258789%;&quot;&gt;&lt;span style=&quot;margin: 0px; padding: 0px; border: 0px; outline: 0px; vertical-align: baseline; font-style: italic;&quot;&gt;&lt;span style=&quot;margin: 0px; padding: 0px; border: 0px; outline: 0px; vertical-align: baseline; line-height: 1.4em;&quot;&gt;Но если бы &quot;&lt;span style=&quot;margin: 0px; padding: 0px; border: 0px; outline: 0px; vertical-align: baseline; font-weight: bold;&quot;&gt;sp&lt;/span&gt;&quot; указывал на какой-нибудь другой тип &quot;&lt;span style=&quot;margin: 0px; padding: 0px; border: 0px; outline: 0px; vertical-align: baseline; font-weight: bold;&quot;&gt;Rectangle&lt;/span&gt;&quot;, то при использовании &quot;cp&quot; получил бы, скорее всего, ошибку. */&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;font_8&quot; style=&quot;margin: 0px; padding: 0px; border: 0px; outline: 0px; vertical-align: baseline; font-size: 14px; line-height: 19.59375px; font-family: &apos;open sans&apos;, sans-serif; max-width: 99.9000015258789%;&quot;&gt;&amp;nbsp;&lt;/p&gt;&lt;p class=&quot;font_8&quot; style=&quot;margin: 0px; padding: 0px; border: 0px; outline: 0px; vertical-align: baseline; font-size: 14px; line-height: 19.59375px; font-family: &apos;open sans&apos;, sans-serif; max-width: 99.9000015258789%;&quot;&gt;&lt;span style=&quot;margin: 0px; padding: 0px; border: 0px; outline: 0px; vertical-align: baseline; font-weight: bold;&quot;&gt;Вывод:&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;margin: 0px; padding: 0px; border: 0px; outline: 0px; vertical-align: baseline; font-weight: bold;&quot;&gt;static_cast&lt;/span&gt;&amp;nbsp;не меняет квалификаторы типа так, как это может&amp;nbsp;&lt;span style=&quot;margin: 0px; padding: 0px; border: 0px; outline: 0px; vertical-align: baseline; font-weight: bold;&quot;&gt;const_cast&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;font_8&quot; style=&quot;margin: 0px; padding: 0px; border: 0px; outline: 0px; vertical-align: baseline; font-size: 14px; line-height: 19.59375px; font-family: &apos;open sans&apos;, sans-serif; max-width: 99.9000015258789%;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; const Shape* &amp;nbsp;getShape() &amp;nbsp; {&amp;nbsp;&lt;span style=&quot;margin: 0px; padding: 0px; border: 0px; outline: 0px; vertical-align: baseline; font-style: italic;&quot;&gt;/* тело функции */&lt;/span&gt;&amp;nbsp;}&lt;/p&gt;&lt;p class=&quot;font_8&quot; style=&quot;margin: 0px; padding: 0px; border: 0px; outline: 0px; vertical-align: baseline; font-size: 14px; line-height: 19.59375px; font-family: &apos;open sans&apos;, sans-serif; max-width: 99.9000015258789%;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; Circle* &amp;nbsp;cp = static_cast &lt; Circle* &amp;gt; ( &amp;nbsp; &amp;nbsp; &amp;nbsp;const_cast &lt;Shape* &amp;gt; ( &amp;nbsp;getShape() &amp;nbsp;) &amp;nbsp; &amp;nbsp; &amp;nbsp;);&amp;nbsp;&amp;nbsp;&lt;/p&gt;&lt;p class=&quot;font_8&quot; style=&quot;margin: 0px; padding: 0px; border: 0px; outline: 0px; vertical-align: baseline; font-size: 14px; line-height: 19.59375px; font-family: &apos;open sans&apos;, sans-serif; max-width: 99.9000015258789%;&quot;&gt;&amp;nbsp;&lt;/p&gt;&lt;p class=&quot;font_8&quot; style=&quot;margin: 0px; padding: 0px; border: 0px; outline: 0px; vertical-align: baseline; font-size: 14px; line-height: 19.59375px; font-family: &apos;open sans&apos;, sans-serif; max-width: 99.9000015258789%;&quot;&gt;&lt;span class=&quot;color_23&quot; style=&quot;margin: 0px; padding: 0px; border: 0px; outline: 0px; vertical-align: baseline;&quot;&gt;/*********************************************************************************************&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;font_8&quot; style=&quot;margin: 0px; padding: 0px; border: 0px; outline: 0px; vertical-align: baseline; font-size: 14px; line-height: 19.59375px; font-family: &apos;open sans&apos;, sans-serif; max-width: 99.9000015258789%;&quot;&gt;&lt;span class=&quot;color_23&quot; style=&quot;margin: 0px; padding: 0px; border: 0px; outline: 0px; vertical-align: baseline;&quot;&gt;**********************************************************************************************&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;font_8&quot; style=&quot;margin: 0px; padding: 0px; border: 0px; outline: 0px; vertical-align: baseline; font-size: 14px; line-height: 19.59375px; font-family: &apos;open sans&apos;, sans-serif; max-width: 99.9000015258789%;&quot;&gt;&lt;span class=&quot;color_23&quot; style=&quot;margin: 0px; padding: 0px; border: 0px; outline: 0px; vertical-align: baseline;&quot;&gt;*********************************************************************************************/&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;font_8&quot; style=&quot;margin: 0px; padding: 0px; border: 0px; outline: 0px; vertical-align: baseline; font-size: 14px; line-height: 19.59375px; font-family: &apos;open sans&apos;, sans-serif; max-width: 99.9000015258789%;&quot;&gt;&lt;span style=&quot;margin: 0px; padding: 0px; border: 0px; outline: 0px; vertical-align: baseline; line-height: 1.4em;&quot;&gt;&lt;span style=&quot;margin: 0px; padding: 0px; border: 0px; outline: 0px; vertical-align: baseline; font-weight: bold;&quot;&gt;Третий:&lt;/span&gt;&amp;nbsp;reintepret_cast &lt; type &amp;gt; ( type2 );&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;font_8&quot; style=&quot;margin: 0px; padding: 0px; border: 0px; outline: 0px; vertical-align: baseline; font-size: 14px; line-height: 19.59375px; font-family: &apos;open sans&apos;, sans-serif; max-width: 99.9000015258789%;&quot;&gt;&lt;span style=&quot;margin: 0px; padding: 0px; border: 0px; outline: 0px; vertical-align: baseline; font-style: italic;&quot;&gt;&lt;span style=&quot;margin: 0px; padding: 0px; border: 0px; outline: 0px; vertical-align: baseline; line-height: 1.4em;&quot;&gt;/* Обычно работает с битами объекта и позволяет осуществлять преобразования между совершенно несвязными типами. &amp;nbsp;*/&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;font_8&quot; style=&quot;margin: 0px; padding: 0px; border: 0px; outline: 0px; vertical-align: baseline; font-size: 14px; line-height: 19.59375px; font-family: &apos;open sans&apos;, sans-serif; max-width: 99.9000015258789%;&quot;&gt;&lt;span style=&quot;margin: 0px; padding: 0px; border: 0px; outline: 0px; vertical-align: baseline; line-height: 1.4em;&quot;&gt;&amp;nbsp; &amp;nbsp; HP = reinterpret_cast &lt; char* &amp;gt; ( 0x0f0... )&amp;nbsp;&lt;span style=&quot;margin: 0px; padding: 0px; border: 0px; outline: 0px; vertical-align: baseline; font-style: italic;&quot;&gt;/* преобразует целое в указатель */&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;font_8&quot; style=&quot;margin: 0px; padding: 0px; border: 0px; outline: 0px; vertical-align: baseline; font-size: 14px; line-height: 19.59375px; font-family: &apos;open sans&apos;, sans-serif; max-width: 99.9000015258789%;&quot;&gt;&lt;span style=&quot;margin: 0px; padding: 0px; border: 0px; outline: 0px; vertical-align: baseline; line-height: 1.4em;&quot;&gt;&amp;nbsp; &amp;nbsp;&lt;span style=&quot;margin: 0px; padding: 0px; border: 0px; outline: 0px; vertical-align: baseline; font-style: italic;&quot;&gt;&amp;nbsp;/* теперь будем преобразовывать&amp;nbsp;&lt;span style=&quot;margin: 0px; padding: 0px; border: 0px; outline: 0px; vertical-align: baseline; font-weight: bold;&quot;&gt;char*&lt;/span&gt;&amp;nbsp;в&amp;nbsp;&lt;span style=&quot;margin: 0px; padding: 0px; border: 0px; outline: 0px; vertical-align: baseline; font-weight: bold;&quot;&gt;int*&amp;nbsp;&lt;/span&gt;*/&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;font_8&quot; style=&quot;margin: 0px; padding: 0px; border: 0px; outline: 0px; vertical-align: baseline; font-size: 14px; line-height: 19.59375px; font-family: &apos;open sans&apos;, sans-serif; max-width: 99.9000015258789%;&quot;&gt;&lt;span style=&quot;margin: 0px; padding: 0px; border: 0px; outline: 0px; vertical-align: baseline; line-height: 1.4em;&quot;&gt;&amp;nbsp; &amp;nbsp; int* PW = reinterpret_cast &lt; int* &amp;gt; ( HP );&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;font_8&quot; style=&quot;margin: 0px; padding: 0px; border: 0px; outline: 0px; vertical-align: baseline; font-size: 14px; line-height: 19.59375px; font-family: &apos;open sans&apos;, sans-serif; max-width: 99.9000015258789%;&quot;&gt;&amp;nbsp;&lt;/p&gt;&lt;p class=&quot;font_8&quot; style=&quot;margin: 0px; padding: 0px; border: 0px; outline: 0px; vertical-align: baseline; font-size: 14px; line-height: 19.59375px; font-family: &apos;open sans&apos;, sans-serif; max-width: 99.9000015258789%;&quot;&gt;&lt;span style=&quot;margin: 0px; padding: 0px; border: 0px; outline: 0px; vertical-align: baseline; font-weight: bold;&quot;&gt;&lt;span style=&quot;margin: 0px; padding: 0px; border: 0px; outline: 0px; vertical-align: baseline; line-height: 1.4em;&quot;&gt;Выводы:&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;margin: 0px; padding: 0px; border: 0px; outline: 0px; vertical-align: baseline; line-height: 1.4em;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;font_8&quot; style=&quot;margin: 0px; padding: 0px; border: 0px; outline: 0px; vertical-align: baseline; font-size: 14px; line-height: 19.59375px; font-family: &apos;open sans&apos;, sans-serif; max-width: 99.9000015258789%;&quot;&gt;&lt;span style=&quot;margin: 0px; padding: 0px; border: 0px; outline: 0px; vertical-align: baseline; line-height: 1.4em;&quot;&gt;&amp;nbsp; 1) Такие преобразования в коде низкого уровня не являются непереносимыми.&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;font_8&quot; style=&quot;margin: 0px; padding: 0px; border: 0px; outline: 0px; vertical-align: baseline; font-size: 14px; line-height: 19.59375px; font-family: &apos;open sans&apos;, sans-serif; max-width: 99.9000015258789%;&quot;&gt;&lt;span style=&quot;margin: 0px; padding: 0px; border: 0px; outline: 0px; vertical-align: baseline; line-height: 1.4em;&quot;&gt;&amp;nbsp; 2)&amp;nbsp;&lt;span style=&quot;margin: 0px; padding: 0px; border: 0px; outline: 0px; vertical-align: baseline; font-weight: bold;&quot;&gt;reinterpret_cast&amp;nbsp;&lt;/span&gt;обычно считает, что указатель на базовый класс является указателем на производный класс и не меняет его значение. А&amp;nbsp;&lt;span style=&quot;margin: 0px; padding: 0px; border: 0px; outline: 0px; vertical-align: baseline; font-weight: bold;&quot;&gt;static_cast&lt;/span&gt;&amp;nbsp;осуществляет правильную работу с адресами.&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;font_8&quot; style=&quot;margin: 0px; padding: 0px; border: 0px; outline: 0px; vertical-align: baseline; font-size: 14px; line-height: 19.59375px; font-family: &apos;open sans&apos;, sans-serif; max-width: 99.9000015258789%;&quot;&gt;&amp;nbsp;&lt;/p&gt;&lt;p class=&quot;font_8&quot; style=&quot;margin: 0px; padding: 0px; border: 0px; outline: 0px; vertical-align: baseline; font-size: 14px; line-height: 19.59375px; font-family: &apos;open sans&apos;, sans-serif; max-width: 99.9000015258789%;&quot;&gt;&lt;span class=&quot;color_23&quot; style=&quot;margin: 0px; padding: 0px; border: 0px; outline: 0px; vertical-align: baseline;&quot;&gt;/*********************************************************************************************&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;font_8&quot; style=&quot;margin: 0px; padding: 0px; border: 0px; outline: 0px; vertical-align: baseline; font-size: 14px; line-height: 19.59375px; font-family: &apos;open sans&apos;, sans-serif; max-width: 99.9000015258789%;&quot;&gt;&lt;span class=&quot;color_23&quot; style=&quot;margin: 0px; padding: 0px; border: 0px; outline: 0px; vertical-align: baseline;&quot;&gt;**********************************************************************************************&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;font_8&quot; style=&quot;margin: 0px; padding: 0px; border: 0px; outline: 0px; vertical-align: baseline; font-size: 14px; line-height: 19.59375px; font-family: &apos;open sans&apos;, sans-serif; max-width: 99.9000015258789%;&quot;&gt;&lt;span class=&quot;color_23&quot; style=&quot;margin: 0px; padding: 0px; border: 0px; outline: 0px; vertical-align: baseline;&quot;&gt;*********************************************************************************************/&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;font_8&quot; style=&quot;margin: 0px; padding: 0px; border: 0px; outline: 0px; vertical-align: baseline; font-size: 14px; line-height: 19.59375px; font-family: &apos;open sans&apos;, sans-serif; max-width: 99.9000015258789%;&quot;&gt;&lt;span style=&quot;margin: 0px; padding: 0px; border: 0px; outline: 0px; vertical-align: baseline; font-weight: bold;&quot;&gt;Четвёртый:&lt;/span&gt;&amp;nbsp;dynamic_cast &amp;nbsp;&lt;/p&gt;&lt;p class=&quot;font_8&quot; style=&quot;margin: 0px; padding: 0px; border: 0px; outline: 0px; vertical-align: baseline; font-size: 14px; line-height: 19.59375px; font-family: &apos;open sans&apos;, sans-serif; max-width: 99.9000015258789%;&quot;&gt;/* Обычно применяется для безопасного нисходящего приведения от указателя на базовый класс к указателю на производный класс.&lt;/p&gt;&lt;p class=&quot;font_8&quot; style=&quot;margin: 0px; padding: 0px; border: 0px; outline: 0px; vertical-align: baseline; font-size: 14px; line-height: 19.59375px; font-family: &apos;open sans&apos;, sans-serif; max-width: 99.9000015258789%;&quot;&gt;&amp;nbsp; &amp;nbsp; От&amp;nbsp;&lt;span style=&quot;margin: 0px; padding: 0px; border: 0px; outline: 0px; vertical-align: baseline; font-weight: bold;&quot;&gt;static_cast&lt;/span&gt;&amp;nbsp;отличается тем, что нисходящее преобразование может осуществляться только для полиморфного типа ( то есть тип приводимого выражения должен быть указателем на тип класса с виртуальной функцией ).&lt;/p&gt;&lt;p class=&quot;font_8&quot; style=&quot;margin: 0px; padding: 0px; border: 0px; outline: 0px; vertical-align: baseline; font-size: 14px; line-height: 19.59375px; font-family: &apos;open sans&apos;, sans-serif; max-width: 99.9000015258789%;&quot;&gt;&amp;nbsp; &amp;nbsp;Правильность приведения проверяется во время выполнения. И если у&amp;nbsp;&lt;span style=&quot;margin: 0px; padding: 0px; border: 0px; outline: 0px; vertical-align: baseline; font-weight: bold;&quot;&gt;statc_cast&lt;/span&gt;&amp;nbsp;издержки времени минимальны, то&amp;nbsp;&lt;span style=&quot;margin: 0px; padding: 0px; border: 0px; outline: 0px; vertical-align: baseline; font-weight: bold;&quot;&gt;dynamic_cast&lt;/span&gt;&amp;nbsp;предполагает более существенные издержки времени выполнения.&lt;/p&gt;&lt;p class=&quot;font_8&quot; style=&quot;margin: 0px; padding: 0px; border: 0px; outline: 0px; vertical-align: baseline; font-size: 14px; line-height: 19.59375px; font-family: &apos;open sans&apos;, sans-serif; max-width: 99.9000015258789%;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;const Circle* cp = dynamic_cast &lt; const Circle* &amp;gt; ( &amp;nbsp;getShape() &amp;nbsp;);&lt;/p&gt;&lt;p class=&quot;font_8&quot; style=&quot;margin: 0px; padding: 0px; border: 0px; outline: 0px; vertical-align: baseline; font-size: 14px; line-height: 19.59375px; font-family: &apos;open sans&apos;, sans-serif; max-width: 99.9000015258789%;&quot;&gt;/* Если getShape возвращает указатель на Circle (или какой-то наследуемый от Circle класс), то приведение будет успешным и cp будет указывать на Circle. Иначе cp будет нулевым.&lt;/p&gt;&lt;p class=&quot;font_8&quot; style=&quot;margin: 0px; padding: 0px; border: 0px; outline: 0px; vertical-align: baseline; font-size: 14px; line-height: 19.59375px; font-family: &apos;open sans&apos;, sans-serif; max-width: 99.9000015258789%;&quot;&gt;&amp;nbsp; &amp;nbsp; Удобно в if ( &amp;nbsp;) &amp;nbsp; { /* &amp;nbsp; */} поместить объявление &quot;const Circle* ... &quot;. Тогда cp, когда в нём исчезнет необходимость, сам уйдёт из области видимости.&lt;/p&gt;&lt;p class=&quot;font_8&quot; style=&quot;margin: 0px; padding: 0px; border: 0px; outline: 0px; vertical-align: baseline; font-size: 14px; line-height: 19.59375px; font-family: &apos;open sans&apos;, sans-serif; max-width: 99.9000015258789%;&quot;&gt;&amp;nbsp;&lt;/p&gt;&lt;p class=&quot;font_8&quot; style=&quot;margin: 0px; padding: 0px; border: 0px; outline: 0px; vertical-align: baseline; font-size: 14px; line-height: 19.59375px; font-family: &apos;open sans&apos;, sans-serif; max-width: 99.9000015258789%;&quot;&gt;&amp;nbsp; &amp;nbsp; const Circle&amp;amp; rc = dynamic_cast &lt; const Circle&amp;amp; &amp;gt; ( &amp;nbsp;*getShape( ) &amp;nbsp;);&lt;/p&gt;&lt;p class=&quot;font_8&quot; style=&quot;margin: 0px; padding: 0px; border: 0px; outline: 0px; vertical-align: baseline; font-size: 14px; line-height: 19.59375px; font-family: &apos;open sans&apos;, sans-serif; max-width: 99.9000015258789%;&quot;&gt;&lt;span style=&quot;margin: 0px; padding: 0px; border: 0px; outline: 0px; vertical-align: baseline; font-style: italic;&quot;&gt;/*Приведение аналогично,но вместо возврата нулевого указателя формирует исключение std::bad_cast *&lt;/span&gt;/&lt;/p&gt;&lt;p class=&quot;font_8&quot; style=&quot;margin: 0px; padding: 0px; border: 0px; outline: 0px; vertical-align: baseline; font-size: 14px; line-height: 19.59375px; font-family: &apos;open sans&apos;, sans-serif; max-width: 99.9000015258789%;&quot;&gt;&amp;nbsp;&lt;/p&gt;&lt;p class=&quot;font_8&quot; style=&quot;margin: 0px; padding: 0px; border: 0px; outline: 0px; vertical-align: baseline; font-size: 14px; line-height: 19.59375px; font-family: &apos;open sans&apos;, sans-serif; max-width: 99.9000015258789%;&quot;&gt;&lt;span style=&quot;margin: 0px; padding: 0px; border: 0px; outline: 0px; vertical-align: baseline; line-height: 1.4em;&quot;&gt;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span style=&quot;margin: 0px; padding: 0px; border: 0px; outline: 0px; vertical-align: baseline; line-height: 1.4em; font-weight: bold;&quot;&gt;Применение dynamic_cast к указателю это вопрос&lt;/span&gt;&lt;span style=&quot;margin: 0px; padding: 0px; border: 0px; outline: 0px; vertical-align: baseline; line-height: 1.4em;&quot;&gt;:&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;font_8&quot; style=&quot;margin: 0px; padding: 0px; border: 0px; outline: 0px; vertical-align: baseline; font-size: 14px; line-height: 19.59375px; font-family: &apos;open sans&apos;, sans-serif; max-width: 99.9000015258789%;&quot;&gt;&quot;Этот указатель на Shape фактически указывает на Circle? Если нет, я могу заняться этим!&quot;&lt;/p&gt;&lt;p class=&quot;font_8&quot; style=&quot;margin: 0px; padding: 0px; border: 0px; outline: 0px; vertical-align: baseline; font-size: 14px; line-height: 19.59375px; font-family: &apos;open sans&apos;, sans-serif; max-width: 99.9000015258789%;&quot;&gt;&amp;nbsp;&lt;/p&gt;&lt;p class=&quot;font_8&quot; style=&quot;margin: 0px; padding: 0px; border: 0px; outline: 0px; vertical-align: baseline; font-size: 14px; line-height: 19.59375px; font-family: &apos;open sans&apos;, sans-serif; max-width: 99.9000015258789%;&quot;&gt;&amp;nbsp; &amp;nbsp;&lt;span style=&quot;margin: 0px; padding: 0px; border: 0px; outline: 0px; vertical-align: baseline; font-weight: bold;&quot;&gt;Применение dynamic_cast к ссылке это утверждение&lt;/span&gt;:&lt;/p&gt;&lt;p class=&quot;font_8&quot; style=&quot;margin: 0px; padding: 0px; border: 0px; outline: 0px; vertical-align: baseline; font-size: 14px; line-height: 19.59375px; font-family: &apos;open sans&apos;, sans-serif; max-width: 99.9000015258789%;&quot;&gt;&quot;Предполагается, что этот Shape есть не что иное, как Circle. Если это не так, значит что-то не в порядке!&quot;&lt;/p&gt;</content:encoded>
			<link>https://it-solutions.ucoz.ru/blog/type_change/2013-11-18-4</link>
			<category>С/C++</category>
			<dc:creator>B@R_LOG</dc:creator>
			<guid>https://it-solutions.ucoz.ru/blog/type_change/2013-11-18-4</guid>
			<pubDate>Mon, 18 Nov 2013 02:14:07 GMT</pubDate>
		</item>
		<item>
			<title>Контроль ввода в C и С++:</title>
			<description>&lt;span style=&quot;font-family: Cambria, serif; font-size: 14pt; line-height: 22.399999618530273px;&quot;&gt;Я думаю многие начинающие программисты С/C++&amp;nbsp;хотели, чтобы при запросе о вводе целого числа пользователь мог ввести только его, а никак не double или char, который преобразовывается в int.&amp;nbsp;&lt;/span&gt;</description>
			<content:encoded>&lt;p class=&quot;font8&quot; style=&quot;margin:0cm;margin-bottom:.0001pt;line-height:16.8pt;
vertical-align:baseline&quot;&gt;&lt;span style=&quot;font-family: Cambria, serif; border: 1pt none windowtext; padding: 0cm; font-size: 14pt;&quot;&gt;Я думаю многие начинающие программисты С/C++&amp;nbsp;хотели, чтобы
при запросе о вводе целого числа пользователь мог ввести только его, а никак не
double или char, который преобразовывается в int.&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-family: Cambria, serif;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;font8&quot; style=&quot;margin: 0cm 0cm 0.0001pt; line-height: 16.8pt; vertical-align: baseline; outline: 0px;&quot;&gt;&lt;span style=&quot;font-family: Cambria, serif;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-family: Cambria, serif;&quot;&gt;&lt;o:p style=&quot;font-size: 10pt;&quot;&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;font8&quot; style=&quot;margin: 0cm 0cm 0.0001pt; line-height: 16.8pt; vertical-align: baseline; outline: 0px;&quot;&gt;&lt;font size=&quot;2&quot;&gt;&lt;span style=&quot;outline: 0px&quot;&gt;&lt;span style=&quot;font-family: Cambria, serif; border: 1pt none windowtext; padding: 0cm;&quot;&gt;Сегодня
я опишу как это сделать.&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: Cambria, serif;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/font&gt;&lt;/p&gt;&lt;p class=&quot;font8&quot; style=&quot;margin: 0cm 0cm 0.0001pt; line-height: 16.8pt; vertical-align: baseline; outline: 0px;&quot;&gt;&lt;font size=&quot;2&quot;&gt;&lt;span style=&quot;font-family: Cambria, serif;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-family: Cambria, serif;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/font&gt;&lt;/p&gt;&lt;p class=&quot;font8&quot; style=&quot;margin: 0cm 0cm 0.0001pt; line-height: 16.8pt; vertical-align: baseline; outline: 0px;&quot;&gt;&lt;font size=&quot;2&quot;&gt;&lt;span style=&quot;font-family: Cambria, serif;&quot;&gt;#include &lt;iostream&amp;gt;&lt;br&gt;
using namespace std;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-family: Cambria, serif;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/font&gt;&lt;/p&gt;&lt;p class=&quot;font8&quot; style=&quot;margin: 0cm 0cm 0.0001pt; line-height: 16.8pt; vertical-align: baseline; outline: 0px;&quot;&gt;&lt;font size=&quot;2&quot;&gt;&lt;span style=&quot;font-family:&quot;Cambria&quot;,&quot;serif&quot;;
mso-ascii-theme-font:major-latin;mso-hansi-theme-font:major-latin;mso-bidi-font-family:
Arial;color:gold&quot;&gt;/* Функция, восстанавливающая поток ввода в случае ошибки.*/&lt;/span&gt;&lt;span style=&quot;font-family: Cambria, serif;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/font&gt;&lt;/p&gt;&lt;p class=&quot;font8&quot; style=&quot;margin: 0cm 0cm 0.0001pt; line-height: 16.8pt; vertical-align: baseline; outline: 0px;&quot;&gt;&lt;font size=&quot;2&quot;&gt;&lt;span style=&quot;outline: 0px&quot;&gt;&lt;span style=&quot;font-family: Cambria, serif; border: 1pt none windowtext; padding: 0cm;&quot;&gt;void
skip_to_int()&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: Cambria, serif;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/font&gt;&lt;/p&gt;&lt;p class=&quot;font8&quot; style=&quot;margin: 0cm 0cm 0.0001pt; line-height: 16.8pt; vertical-align: baseline; outline: 0px;&quot;&gt;&lt;font size=&quot;2&quot;&gt;&lt;span style=&quot;outline: 0px&quot;&gt;&lt;span style=&quot;font-family: Cambria, serif; border: 1pt none windowtext; padding: 0cm;&quot;&gt;{&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: Cambria, serif;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/font&gt;&lt;/p&gt;&lt;p class=&quot;font8&quot; style=&quot;margin: 0cm 0cm 0.0001pt; line-height: 16.8pt; vertical-align: baseline; outline: 0px;&quot;&gt;&lt;font size=&quot;2&quot;&gt;&lt;span style=&quot;outline: 0px&quot;&gt;&lt;span style=&quot;font-family: Cambria, serif; border: 1pt none windowtext; padding: 0cm;&quot;&gt;&amp;nbsp;&amp;nbsp;
&amp;nbsp;if (cin.fail() )&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: Cambria, serif;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/font&gt;&lt;/p&gt;&lt;p class=&quot;font8&quot; style=&quot;margin: 0cm 0cm 0.0001pt; line-height: 16.8pt; vertical-align: baseline; outline: 0px;&quot;&gt;&lt;font size=&quot;2&quot;&gt;&lt;span style=&quot;outline: 0px&quot;&gt;&lt;span style=&quot;font-family: Cambria, serif; border: 1pt none windowtext; padding: 0cm;&quot;&gt;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;{&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: Cambria, serif;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/font&gt;&lt;/p&gt;&lt;p class=&quot;font8&quot; style=&quot;margin: 0cm 0cm 0.0001pt; line-height: 16.8pt; vertical-align: baseline; outline: 0px;&quot;&gt;&lt;font size=&quot;2&quot;&gt;&lt;span style=&quot;outline: 0px&quot;&gt;&lt;span style=&quot;font-family: Cambria, serif; border: 1pt none windowtext; padding: 0cm;&quot;&gt;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp;cin.clear();&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: Cambria, serif;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/font&gt;&lt;/p&gt;&lt;p class=&quot;font8&quot; style=&quot;margin: 0cm 0cm 0.0001pt; line-height: 16.8pt; vertical-align: baseline; outline: 0px;&quot;&gt;&lt;font size=&quot;2&quot;&gt;&lt;span style=&quot;outline: 0px&quot;&gt;&lt;span style=&quot;font-family: Cambria, serif; border: 1pt none windowtext; padding: 0cm;&quot;&gt;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp;char ch;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: Cambria, serif;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/font&gt;&lt;/p&gt;&lt;p class=&quot;font8&quot; style=&quot;margin: 0cm 0cm 0.0001pt; line-height: 16.8pt; vertical-align: baseline; outline: 0px;&quot;&gt;&lt;font size=&quot;2&quot;&gt;&lt;span style=&quot;outline: 0px&quot;&gt;&lt;span style=&quot;font-family: Cambria, serif; border: 1pt none windowtext; padding: 0cm;&quot;&gt;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp;while ( cin &amp;gt;&amp;gt; ch &amp;amp;&amp;amp; !(
isdigit(ch) ) );&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: Cambria, serif;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/font&gt;&lt;/p&gt;&lt;p class=&quot;font8&quot; style=&quot;margin: 0cm 0cm 0.0001pt; line-height: 16.8pt; vertical-align: baseline; outline: 0px;&quot;&gt;&lt;font size=&quot;2&quot;&gt;&lt;span style=&quot;outline: 0px&quot;&gt;&lt;span style=&quot;font-family: Cambria, serif; border: 1pt none windowtext; padding: 0cm;&quot;&gt;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; if (!cin) cerr &lt;&lt; (&quot;Is not
input&quot;);&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: Cambria, serif;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/font&gt;&lt;/p&gt;&lt;p class=&quot;font8&quot; style=&quot;margin: 0cm 0cm 0.0001pt; line-height: 16.8pt; vertical-align: baseline; outline: 0px;&quot;&gt;&lt;font size=&quot;2&quot;&gt;&lt;span style=&quot;outline: 0px&quot;&gt;&lt;span style=&quot;font-family: Cambria, serif; border: 1pt none windowtext; padding: 0cm;&quot;&gt;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; cin.unget();&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: Cambria, serif;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/font&gt;&lt;/p&gt;&lt;p class=&quot;font8&quot; style=&quot;margin: 0cm 0cm 0.0001pt; line-height: 16.8pt; vertical-align: baseline; outline: 0px;&quot;&gt;&lt;font size=&quot;2&quot;&gt;&lt;span style=&quot;outline: 0px&quot;&gt;&lt;span style=&quot;font-family: Cambria, serif; border: 1pt none windowtext; padding: 0cm;&quot;&gt;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp; }&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: Cambria, serif;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/font&gt;&lt;/p&gt;&lt;p class=&quot;font8&quot; style=&quot;margin: 0cm 0cm 0.0001pt; line-height: 16.8pt; vertical-align: baseline; outline: 0px;&quot;&gt;&lt;font size=&quot;2&quot;&gt;&lt;span style=&quot;outline: 0px&quot;&gt;&lt;span style=&quot;font-family: Cambria, serif; border: 1pt none windowtext; padding: 0cm;&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: Cambria, serif;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/font&gt;&lt;/p&gt;&lt;p class=&quot;font8&quot; style=&quot;margin: 0cm 0cm 0.0001pt; line-height: 16.8pt; vertical-align: baseline; outline: 0px;&quot;&gt;&lt;font size=&quot;2&quot;&gt;&lt;span style=&quot;font-family: Cambria, serif;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-family: Cambria, serif;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/font&gt;&lt;/p&gt;&lt;p class=&quot;font8&quot; style=&quot;margin: 0cm 0cm 0.0001pt; line-height: 16.8pt; vertical-align: baseline; outline: 0px;&quot;&gt;&lt;font size=&quot;2&quot;&gt;&lt;span style=&quot;font-family: Cambria, serif;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-family: Cambria, serif;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/font&gt;&lt;/p&gt;&lt;p class=&quot;font8&quot; style=&quot;margin: 0cm 0cm 0.0001pt; line-height: 16.8pt; vertical-align: baseline; outline: 0px;&quot;&gt;&lt;font size=&quot;2&quot;&gt;&lt;span style=&quot;font-family:&quot;Cambria&quot;,&quot;serif&quot;;
mso-ascii-theme-font:major-latin;mso-hansi-theme-font:major-latin;mso-bidi-font-family:
Arial;color:gold&quot;&gt;/*&lt;span class=&quot;apple-converted-space&quot;&gt;&amp;nbsp;&lt;/span&gt;Собственно
это и есть вызываемая функция, не позволяющая ввести&amp;nbsp;значение&amp;nbsp;другого
типа.&lt;/span&gt;&lt;span style=&quot;font-family: Cambria, serif;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/font&gt;&lt;/p&gt;&lt;p class=&quot;font8&quot; style=&quot;margin: 0cm 0cm 0.0001pt; line-height: 16.8pt; vertical-align: baseline; outline: 0px;&quot;&gt;&lt;font size=&quot;2&quot;&gt;&lt;span style=&quot;font-family:&quot;Cambria&quot;,&quot;serif&quot;;
mso-ascii-theme-font:major-latin;mso-hansi-theme-font:major-latin;mso-bidi-font-family:
Arial;color:gold&quot;&gt;Например, если хотим ввести значение&amp;nbsp;типа bool,
то&amp;nbsp;пишем:&lt;br&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; bool value = -1;&lt;/span&gt;&lt;span style=&quot;font-family: Cambria, serif;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/font&gt;&lt;/p&gt;&lt;p class=&quot;font8&quot; style=&quot;margin: 0cm 0cm 0.0001pt; line-height: 16.8pt; vertical-align: baseline; outline: 0px;&quot;&gt;&lt;font size=&quot;2&quot;&gt;&lt;span style=&quot;font-family:&quot;Cambria&quot;,&quot;serif&quot;;
mso-ascii-theme-font:major-latin;mso-hansi-theme-font:major-latin;mso-bidi-font-family:
Arial;color:gold&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; value = the_contol_input
&lt;bool&amp;gt;&amp;nbsp;;&lt;/span&gt;&lt;span style=&quot;font-family: Cambria, serif;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/font&gt;&lt;/p&gt;&lt;p class=&quot;font8&quot; style=&quot;margin: 0cm 0cm 0.0001pt; line-height: 16.8pt; vertical-align: baseline; outline: 0px;&quot;&gt;&lt;font size=&quot;2&quot;&gt;&lt;span style=&quot;outline: 0px&quot;&gt;&lt;span style=&quot;font-family:&quot;Cambria&quot;,&quot;serif&quot;;mso-ascii-theme-font:major-latin;
mso-hansi-theme-font:major-latin;mso-bidi-font-family:Arial;color:gold;
border:none windowtext 1.0pt;mso-border-alt:none windowtext 0cm;padding:0cm&quot;&gt;И
ввод&amp;nbsp;будет продолжаться до тех пор, пока не введём 0 или 1.*/&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: Cambria, serif;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/font&gt;&lt;/p&gt;&lt;p class=&quot;font8&quot; style=&quot;margin: 0cm 0cm 0.0001pt; line-height: 16.8pt; vertical-align: baseline; outline: 0px;&quot;&gt;&lt;font size=&quot;2&quot;&gt;&lt;span style=&quot;font-family: Cambria, serif;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-family: Cambria, serif;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/font&gt;&lt;/p&gt;&lt;p class=&quot;font8&quot; style=&quot;margin: 0cm 0cm 0.0001pt; line-height: 16.8pt; vertical-align: baseline; outline: 0px;&quot;&gt;&lt;font size=&quot;2&quot;&gt;&lt;span style=&quot;outline: 0px&quot;&gt;&lt;span style=&quot;font-family: Cambria, serif; border: 1pt none windowtext; padding: 0cm;&quot;&gt;template
&lt;typename Type&amp;gt;&lt;span class=&quot;apple-converted-space&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family:&quot;Cambria&quot;,&quot;serif&quot;;mso-ascii-theme-font:major-latin;
mso-hansi-theme-font:major-latin;mso-bidi-font-family:Arial;color:gold;
border:none windowtext 1.0pt;mso-border-alt:none windowtext 0cm;padding:0cm&quot;&gt;&amp;nbsp;/*
напомню, что для шаблонных&amp;nbsp;функций нет разделения на &quot;.cpp&quot; и
&quot;.h&quot;. &amp;nbsp;*/&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: Cambria, serif;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/font&gt;&lt;/p&gt;&lt;p class=&quot;font8&quot; style=&quot;margin: 0cm 0cm 0.0001pt; line-height: 16.8pt; vertical-align: baseline; outline: 0px;&quot;&gt;&lt;font size=&quot;2&quot;&gt;&lt;span style=&quot;outline: 0px&quot;&gt;&lt;span style=&quot;font-family: Cambria, serif; border: 1pt none windowtext; padding: 0cm;&quot;&gt;Type
the_control_input()&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: Cambria, serif;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/font&gt;&lt;/p&gt;&lt;p class=&quot;font8&quot; style=&quot;margin: 0cm 0cm 0.0001pt; line-height: 16.8pt; vertical-align: baseline; outline: 0px;&quot;&gt;&lt;font size=&quot;2&quot;&gt;&lt;span style=&quot;outline: 0px&quot;&gt;&lt;span style=&quot;font-family: Cambria, serif; border: 1pt none windowtext; padding: 0cm;&quot;&gt;{&amp;nbsp;&amp;nbsp;
&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: Cambria, serif;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/font&gt;&lt;/p&gt;&lt;p class=&quot;font8&quot; style=&quot;margin: 0cm 0cm 0.0001pt; line-height: 16.8pt; vertical-align: baseline; outline: 0px;&quot;&gt;&lt;font size=&quot;2&quot;&gt;&lt;span style=&quot;outline: 0px&quot;&gt;&lt;span style=&quot;font-family: Cambria, serif; border: 1pt none windowtext; padding: 0cm;&quot;&gt;&amp;nbsp;&amp;nbsp;
&amp;nbsp;Type n=0;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: Cambria, serif;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/font&gt;&lt;/p&gt;&lt;p class=&quot;font8&quot; style=&quot;margin: 0cm 0cm 0.0001pt; line-height: 16.8pt; vertical-align: baseline; outline: 0px;&quot;&gt;&lt;font size=&quot;2&quot;&gt;&lt;span style=&quot;outline: 0px&quot;&gt;&lt;span style=&quot;font-family: Cambria, serif; border: 1pt none windowtext; padding: 0cm;&quot;&gt;&amp;nbsp;&amp;nbsp;
&amp;nbsp;while (true)&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: Cambria, serif;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/font&gt;&lt;/p&gt;&lt;p class=&quot;font8&quot; style=&quot;margin: 0cm 0cm 0.0001pt; line-height: 16.8pt; vertical-align: baseline; outline: 0px;&quot;&gt;&lt;font size=&quot;2&quot;&gt;&lt;span style=&quot;outline: 0px&quot;&gt;&lt;span style=&quot;font-family: Cambria, serif; border: 1pt none windowtext; padding: 0cm;&quot;&gt;&amp;nbsp;&amp;nbsp;
&amp;nbsp;{&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: Cambria, serif;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/font&gt;&lt;/p&gt;&lt;p class=&quot;font8&quot; style=&quot;margin: 0cm 0cm 0.0001pt; line-height: 16.8pt; vertical-align: baseline; outline: 0px;&quot;&gt;&lt;font size=&quot;2&quot;&gt;&lt;span style=&quot;outline: 0px&quot;&gt;&lt;span style=&quot;font-family: Cambria, serif; border: 1pt none windowtext; padding: 0cm;&quot;&gt;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;if (cin &amp;gt;&amp;gt; n) return n;&lt;/span&gt;&lt;span class=&quot;apple-converted-space&quot;&gt;&lt;span style=&quot;font-family:&quot;Cambria&quot;,&quot;serif&quot;;
mso-ascii-theme-font:major-latin;mso-hansi-theme-font:major-latin;mso-bidi-font-family:
Arial;color:gold;border:none windowtext 1.0pt;mso-border-alt:none windowtext 0cm;
padding:0cm&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family:&quot;Cambria&quot;,&quot;serif&quot;;
mso-ascii-theme-font:major-latin;mso-hansi-theme-font:major-latin;mso-bidi-font-family:
Arial;color:gold;border:none windowtext 1.0pt;mso-border-alt:none windowtext 0cm;
padding:0cm&quot;&gt;/* если введённое значение&amp;nbsp;не принадлежит типу Type - идём
дальше.*/&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: Cambria, serif;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/font&gt;&lt;/p&gt;&lt;p class=&quot;font8&quot; style=&quot;margin: 0cm 0cm 0.0001pt; line-height: 16.8pt; vertical-align: baseline; outline: 0px;&quot;&gt;&lt;font size=&quot;2&quot;&gt;&lt;span style=&quot;outline: 0px&quot;&gt;&lt;span style=&quot;font-family: Cambria, serif; border: 1pt none windowtext; padding: 0cm;&quot;&gt;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;cout &lt;&lt; &quot;It is not number. Repeat
input!&amp;#92;n&quot;;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: Cambria, serif;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/font&gt;&lt;/p&gt;&lt;p class=&quot;font8&quot; style=&quot;margin: 0cm 0cm 0.0001pt; line-height: 16.8pt; vertical-align: baseline; outline: 0px;&quot;&gt;&lt;font size=&quot;2&quot;&gt;&lt;span style=&quot;outline: 0px&quot;&gt;&lt;span style=&quot;font-family: Cambria, serif; border: 1pt none windowtext; padding: 0cm;&quot;&gt;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;skip_to_int();&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: Cambria, serif;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/font&gt;&lt;/p&gt;&lt;p class=&quot;font8&quot; style=&quot;margin: 0cm 0cm 0.0001pt; line-height: 16.8pt; vertical-align: baseline; outline: 0px;&quot;&gt;&lt;font size=&quot;2&quot;&gt;&lt;span style=&quot;outline: 0px&quot;&gt;&lt;span style=&quot;font-family: Cambria, serif; border: 1pt none windowtext; padding: 0cm;&quot;&gt;&amp;nbsp;&amp;nbsp;
&amp;nbsp;}&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: Cambria, serif;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/font&gt;&lt;/p&gt;&lt;p class=&quot;font8&quot; style=&quot;margin: 0cm 0cm 0.0001pt; line-height: 16.8pt; vertical-align: baseline; outline: 0px;&quot;&gt;&lt;font size=&quot;2&quot;&gt;&lt;span style=&quot;outline: 0px&quot;&gt;&lt;span style=&quot;font-family: Cambria, serif; border: 1pt none windowtext; padding: 0cm;&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: Cambria, serif;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/font&gt;&lt;/p&gt;&lt;p class=&quot;font8&quot; style=&quot;margin: 0cm 0cm 0.0001pt; line-height: 16.8pt; vertical-align: baseline; outline: 0px;&quot;&gt;&lt;font size=&quot;2&quot;&gt;&lt;span style=&quot;font-family: Cambria, serif;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-family: Cambria, serif;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/font&gt;&lt;/p&gt;&lt;p class=&quot;font8&quot; style=&quot;margin: 0cm 0cm 0.0001pt; line-height: 16.8pt; vertical-align: baseline; outline: 0px;&quot;&gt;&lt;font size=&quot;2&quot;&gt;&lt;span style=&quot;outline: 0px&quot;&gt;&lt;span style=&quot;font-family: Cambria, serif; border: 1pt none windowtext; padding: 0cm;&quot;&gt;А
теперь поговорим о работе с функциями из файла &lt;iostream&amp;gt;:&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: Cambria, serif;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/font&gt;&lt;/p&gt;&lt;p class=&quot;font8&quot; style=&quot;margin: 0cm 0cm 0.0001pt; line-height: 16.8pt; vertical-align: baseline; outline: 0px;&quot;&gt;&lt;font size=&quot;2&quot;&gt;&lt;span style=&quot;font-family: Cambria, serif;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-family: Cambria, serif;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/font&gt;&lt;/p&gt;&lt;p class=&quot;font8&quot; style=&quot;margin: 0cm 0cm 0.0001pt; line-height: 16.8pt; vertical-align: baseline; outline: 0px;&quot;&gt;&lt;font size=&quot;2&quot;&gt;&lt;span style=&quot;outline: 0px&quot;&gt;&lt;span style=&quot;font-family: Cambria, serif; border: 1pt none windowtext; padding: 0cm;&quot;&gt;Поток
- это последовательность символов, к которым возможен только последовательный
доступ. Извлечённый символ удаляется из потока.&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: Cambria, serif;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/font&gt;&lt;/p&gt;&lt;p class=&quot;font8&quot; style=&quot;margin: 0cm 0cm 0.0001pt; line-height: 16.8pt; vertical-align: baseline; outline: 0px;&quot;&gt;&lt;font size=&quot;2&quot;&gt;&lt;span style=&quot;outline: 0px&quot;&gt;&lt;span style=&quot;font-family: Cambria, serif; border: 1pt none windowtext; padding: 0cm;&quot;&gt;&amp;nbsp;
&amp;nbsp; Если из потока прочитаны не все символы до конца строки ( символ
&quot;&amp;#92;n&quot;) включительно, то после операции чтения поток не будет пустым.&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: Cambria, serif;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/font&gt;&lt;/p&gt;&lt;p class=&quot;font8&quot; style=&quot;margin: 0cm 0cm 0.0001pt; line-height: 16.8pt; vertical-align: baseline; outline: 0px;&quot;&gt;&lt;font size=&quot;2&quot;&gt;&lt;span style=&quot;font-family: Cambria, serif;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-family: Cambria, serif;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/font&gt;&lt;/p&gt;&lt;p class=&quot;font8&quot; style=&quot;margin: 0cm 0cm 0.0001pt; line-height: 16.8pt; vertical-align: baseline; outline: 0px;&quot;&gt;&lt;font size=&quot;2&quot;&gt;&lt;span style=&quot;outline: 0px&quot;&gt;&lt;span style=&quot;font-family:&quot;Cambria&quot;,&quot;serif&quot;;mso-ascii-theme-font:major-latin;
mso-hansi-theme-font:major-latin;mso-bidi-font-family:Arial;color:gold;
border:none windowtext 1.0pt;mso-border-alt:none windowtext 0cm;padding:0cm&quot;&gt;int
istream :: get() -&lt;/span&gt;&lt;span style=&quot;font-family: Cambria, serif; border: 1pt none windowtext; padding: 0cm;&quot;&gt;&amp;nbsp;извлекает из входного потока один символ и возвращает его
int-код&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: Cambria, serif;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/font&gt;&lt;/p&gt;&lt;p class=&quot;font8&quot; style=&quot;margin: 0cm 0cm 0.0001pt; line-height: 16.8pt; vertical-align: baseline; outline: 0px;&quot;&gt;&lt;font size=&quot;2&quot;&gt;&lt;span style=&quot;font-family: Cambria, serif;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-family: Cambria, serif;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/font&gt;&lt;/p&gt;&lt;p class=&quot;font8&quot; style=&quot;margin: 0cm 0cm 0.0001pt; line-height: 16.8pt; vertical-align: baseline; outline: 0px;&quot;&gt;&lt;font size=&quot;2&quot;&gt;&lt;span style=&quot;font-family: Cambria, serif;&quot;&gt;Пример её неправильной работы:&lt;/span&gt;&lt;span style=&quot;font-family: Cambria, serif;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/font&gt;&lt;/p&gt;&lt;p class=&quot;font8&quot; style=&quot;margin: 0cm 0cm 0.0001pt; line-height: 16.8pt; vertical-align: baseline; outline: 0px;&quot;&gt;&lt;font size=&quot;2&quot;&gt;&lt;span style=&quot;outline: 0px&quot;&gt;&lt;span style=&quot;font-family: Cambria, serif; border: 1pt none windowtext; padding: 0cm;&quot;&gt;&amp;nbsp;
&amp;nbsp; cout &lt;&lt; cin.get(); /* набираем abcd и жмём enter */&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: Cambria, serif;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/font&gt;&lt;/p&gt;&lt;p class=&quot;font8&quot; style=&quot;margin: 0cm 0cm 0.0001pt; line-height: 16.8pt; vertical-align: baseline; outline: 0px;&quot;&gt;&lt;font size=&quot;2&quot;&gt;&lt;span style=&quot;outline: 0px&quot;&gt;&lt;span style=&quot;font-family: Cambria, serif; border: 1pt none windowtext; padding: 0cm;&quot;&gt;&amp;nbsp;
&amp;nbsp; cout &lt;&lt; cin.get(); /* программа, вместо того, чтобы ждать 2ого
пользовательского ввода прочитает символ &apos;b&apos; */&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: Cambria, serif;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/font&gt;&lt;/p&gt;&lt;p class=&quot;font8&quot; style=&quot;margin: 0cm 0cm 0.0001pt; line-height: 16.8pt; vertical-align: baseline; outline: 0px;&quot;&gt;&lt;font size=&quot;2&quot;&gt;&lt;span style=&quot;font-family: Cambria, serif;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-family: Cambria, serif;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/font&gt;&lt;/p&gt;&lt;p class=&quot;font8&quot; style=&quot;margin: 0cm 0cm 0.0001pt; line-height: 16.8pt; vertical-align: baseline; outline: 0px;&quot;&gt;&lt;font size=&quot;2&quot;&gt;&lt;span style=&quot;font-family: Cambria, serif;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-family: Cambria, serif;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/font&gt;&lt;/p&gt;&lt;p class=&quot;font8&quot; style=&quot;margin: 0cm 0cm 0.0001pt; line-height: 16.8pt; vertical-align: baseline; outline: 0px;&quot;&gt;&lt;font size=&quot;2&quot;&gt;&lt;span style=&quot;font-family:&quot;Cambria&quot;,&quot;serif&quot;;
mso-ascii-theme-font:major-latin;mso-hansi-theme-font:major-latin;mso-bidi-font-family:
Arial;color:gold&quot;&gt;istream&amp;amp; istream :: ignore (streamsize n=1, int
delim=EOF)&lt;/span&gt;&lt;span class=&quot;apple-converted-space&quot;&gt;&lt;span style=&quot;font-family:
&quot;Cambria&quot;,&quot;serif&quot;;mso-ascii-theme-font:major-latin;mso-hansi-theme-font:major-latin;
mso-bidi-font-family:Arial;color:red&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family:&quot;Cambria&quot;,&quot;serif&quot;;mso-ascii-theme-font:major-latin;
mso-hansi-theme-font:major-latin;mso-bidi-font-family:Arial;color:red&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-family: Cambria, serif;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/font&gt;&lt;/p&gt;&lt;p class=&quot;font8&quot; style=&quot;margin: 0cm 0cm 0.0001pt; line-height: 16.8pt; vertical-align: baseline; outline: 0px;&quot;&gt;&lt;font size=&quot;2&quot;&gt;&lt;span style=&quot;font-family: Cambria, serif; border: 1pt none windowtext; padding: 0cm;&quot;&gt;&lt;span style=&quot;outline: 0px&quot;&gt;Извлекает из потока&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;outline: 0px&quot;&gt;символы и отбрасывает их. Причём поступает так либо с
&quot;n&quot;&amp;nbsp;символами, либо со всеми символами, предшествующими символу
заданному параметром &quot;delim&quot;.&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: Cambria, serif;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/font&gt;&lt;/p&gt;&lt;p class=&quot;font8&quot; style=&quot;margin: 0cm 0cm 0.0001pt; line-height: 16.8pt; vertical-align: baseline; outline: 0px;&quot;&gt;&lt;font size=&quot;2&quot;&gt;&lt;span style=&quot;font-family: Cambria, serif;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-family: Cambria, serif;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/font&gt;&lt;/p&gt;&lt;p class=&quot;font8&quot; style=&quot;margin: 0cm 0cm 0.0001pt; line-height: 16.8pt; vertical-align: baseline; outline: 0px;&quot;&gt;&lt;font size=&quot;2&quot;&gt;&lt;span style=&quot;outline: 0px&quot;&gt;&lt;span style=&quot;font-family: Cambria, serif; border: 1pt none windowtext; padding: 0cm;&quot;&gt;У
потока ввода есть буфер чтения, в котором он хранит символы.&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: Cambria, serif;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/font&gt;&lt;/p&gt;&lt;p class=&quot;font8&quot; style=&quot;margin: 0cm 0cm 0.0001pt; line-height: 16.8pt; vertical-align: baseline; outline: 0px;&quot;&gt;&lt;font size=&quot;2&quot;&gt;&lt;span style=&quot;outline: 0px&quot;&gt;&lt;span style=&quot;font-family: Cambria, serif; border: 1pt none windowtext; padding: 0cm;&quot;&gt;Обращение
к нему через&lt;span class=&quot;apple-converted-space&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family:&quot;Cambria&quot;,&quot;serif&quot;;mso-ascii-theme-font:major-latin;
mso-hansi-theme-font:major-latin;mso-bidi-font-family:Arial;color:gold;
border:none windowtext 1.0pt;mso-border-alt:none windowtext 0cm;padding:0cm&quot;&gt;streambuf*
istream::rdbuf() const;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: Cambria, serif;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/font&gt;&lt;/p&gt;&lt;p class=&quot;font8&quot; style=&quot;margin: 0cm 0cm 0.0001pt; line-height: 16.8pt; vertical-align: baseline; outline: 0px;&quot;&gt;&lt;font size=&quot;2&quot;&gt;&lt;span style=&quot;outline: 0px&quot;&gt;&lt;span style=&quot;font-family: Cambria, serif; border: 1pt none windowtext; padding: 0cm;&quot;&gt;Количество
символов в нём равно&amp;nbsp;&lt;span class=&quot;apple-converted-space&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family:&quot;Cambria&quot;,&quot;serif&quot;;mso-ascii-theme-font:major-latin;
mso-hansi-theme-font:major-latin;mso-bidi-font-family:Arial;color:gold;
border:none windowtext 1.0pt;mso-border-alt:none windowtext 0cm;padding:0cm&quot;&gt;streamsize&amp;nbsp;streambuf::in_avail();&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: Cambria, serif;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/font&gt;&lt;/p&gt;&lt;p class=&quot;font8&quot; style=&quot;margin: 0cm 0cm 0.0001pt; line-height: 16.8pt; vertical-align: baseline; outline: 0px;&quot;&gt;&lt;font size=&quot;2&quot;&gt;&lt;span style=&quot;outline: 0px&quot;&gt;&lt;span style=&quot;font-family: Cambria, serif; border: 1pt none windowtext; padding: 0cm;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: Cambria, serif;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/font&gt;&lt;/p&gt;&lt;p class=&quot;font8&quot; style=&quot;margin: 0cm 0cm 0.0001pt; line-height: 16.8pt; vertical-align: baseline; outline: 0px;&quot;&gt;&lt;font size=&quot;2&quot;&gt;&lt;span style=&quot;outline: 0px&quot;&gt;&lt;span style=&quot;font-family: Cambria, serif; border: 1pt none windowtext; padding: 0cm;&quot;&gt;Пример
их использования:&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: Cambria, serif;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/font&gt;&lt;/p&gt;&lt;p class=&quot;font8&quot; style=&quot;margin: 0cm 0cm 0.0001pt; line-height: 16.8pt; vertical-align: baseline; outline: 0px;&quot;&gt;&lt;font size=&quot;2&quot;&gt;&lt;span style=&quot;outline: 0px&quot;&gt;&lt;span style=&quot;font-family: Cambria, serif; border: 1pt none windowtext; padding: 0cm;&quot;&gt;&amp;nbsp;
&amp;nbsp; cin.ignore ( cin.rdbuf()-&amp;gt;in_avail() );&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: Cambria, serif;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/font&gt;&lt;/p&gt;&lt;p class=&quot;font8&quot; style=&quot;margin: 0cm 0cm 0.0001pt; line-height: 16.8pt; vertical-align: baseline; outline: 0px;&quot;&gt;&lt;font size=&quot;2&quot;&gt;&lt;span style=&quot;font-family: Cambria, serif;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-family: Cambria, serif;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/font&gt;&lt;/p&gt;&lt;p class=&quot;font8&quot; style=&quot;margin: 0cm 0cm 0.0001pt; line-height: 16.8pt; vertical-align: baseline; outline: 0px;&quot;&gt;&lt;font size=&quot;2&quot;&gt;&lt;span style=&quot;font-family:&quot;Cambria&quot;,&quot;serif&quot;;
mso-ascii-theme-font:major-latin;mso-hansi-theme-font:major-latin;mso-bidi-font-family:
Arial;color:gold&quot;&gt;void ios::clear (iostate state = goodbit);&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-family: Cambria, serif;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/font&gt;&lt;/p&gt;&lt;p class=&quot;font8&quot; style=&quot;margin: 0cm 0cm 0.0001pt; line-height: 16.8pt; vertical-align: baseline; outline: 0px;&quot;&gt;&lt;font size=&quot;2&quot;&gt;&lt;span style=&quot;font-family: Cambria, serif;&quot;&gt;Восстанавливает поток (если он оказался в ошибочном
состоянии), делая его работоспособным.&lt;/span&gt;&lt;span style=&quot;font-family: Cambria, serif;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/font&gt;&lt;/p&gt;&lt;p class=&quot;font8&quot; style=&quot;margin: 0cm 0cm 0.0001pt; line-height: 16.8pt; vertical-align: baseline; outline: 0px;&quot;&gt;&lt;font size=&quot;2&quot;&gt;&lt;span style=&quot;font-family: Cambria, serif;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-family: Cambria, serif;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/font&gt;&lt;/p&gt;&lt;p class=&quot;font_8&quot; style=&quot;margin: 0px; padding: 0px; border: 0px; outline: 0px; vertical-align: baseline; line-height: 1.4em;&quot;&gt;

























































































































&lt;/p&gt;&lt;p class=&quot;font8&quot; style=&quot;margin: 0cm 0cm 0.0001pt; line-height: 16.8pt; vertical-align: baseline; outline: 0px;&quot;&gt;&lt;span style=&quot;font-family: Cambria, serif;&quot;&gt;&lt;font size=&quot;2&quot;&gt;Например, при попытке прочитать число, когда в потоке были
буквы,&amp;nbsp;поток переводится в состояние отказа и с ним нельзя работать (с
помощью того же cin.get(); )&lt;/font&gt;&lt;/span&gt;&lt;span style=&quot;font-family: Cambria, serif;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;</content:encoded>
			<link>https://it-solutions.ucoz.ru/blog/control_input/2013-11-18-2</link>
			<category>С/C++</category>
			<dc:creator>B@R_LOG</dc:creator>
			<guid>https://it-solutions.ucoz.ru/blog/control_input/2013-11-18-2</guid>
			<pubDate>Mon, 18 Nov 2013 00:50:34 GMT</pubDate>
		</item>
	</channel>
</rss>