<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title><![CDATA[Linux Forum &mdash; не дружат cin и getchar]]></title>
		<link>https://linuxforum.ru/viewtopic.php?id=21989</link>
		<atom:link href="https://linuxforum.ru/extern.php?action=feed&amp;tid=21989&amp;type=rss" rel="self" type="application/rss+xml" />
		<description><![CDATA[Недавние сообщения в теме «не дружат cin и getchar».]]></description>
		<lastBuildDate>Fri, 04 May 2012 05:47:59 +0000</lastBuildDate>
		<generator>PunBB</generator>
		<item>
			<title><![CDATA[Re: не дружат cin и getchar]]></title>
			<link>https://linuxforum.ru/viewtopic.php?pid=272337#p272337</link>
			<description><![CDATA[<p>огромное спасибо! как только дали направление, куда копать, сразу нашел кучу информации в интернете на эту тему</p>]]></description>
			<author><![CDATA[null@example.com (mokynis)]]></author>
			<pubDate>Fri, 04 May 2012 05:47:59 +0000</pubDate>
			<guid>https://linuxforum.ru/viewtopic.php?pid=272337#p272337</guid>
		</item>
		<item>
			<title><![CDATA[Re: не дружат cin и getchar]]></title>
			<link>https://linuxforum.ru/viewtopic.php?pid=272115#p272115</link>
			<description><![CDATA[<p>после чтения цифры в буфере остаётся &#039;\n&#039;, который читает getchar() поэтому цикл сразу заканчивается.</p><p>ЗЫ: лучше не смешивать методы ввода си и с++. см. ifstream::get()</p>]]></description>
			<author><![CDATA[null@example.com (Fat-Zer)]]></author>
			<pubDate>Thu, 03 May 2012 05:40:47 +0000</pubDate>
			<guid>https://linuxforum.ru/viewtopic.php?pid=272115#p272115</guid>
		</item>
		<item>
			<title><![CDATA[не дружат cin и getchar]]></title>
			<link>https://linuxforum.ru/viewtopic.php?pid=272109#p272109</link>
			<description><![CDATA[<p>помогите разобраться, что за ерунда: сам полдня уже бьюсь и ничего так и не понял. Вот программка</p><div class="codebox"><pre><code>#include &lt;iostream&gt;
#include &lt;stdio.h&gt;

using namespace std;

int main()
{
    const int len=20;
    char sss[len],let=&#039; &#039;;
/*
    int what_run=1;
    cout&lt;&lt;&quot;enter task #:&quot;;
    cin&gt;&gt;what_run;
    if(what_run&lt;1 || what_run&gt;15)
    {
        cout&lt;&lt;&quot;Good bye!&quot;&lt;&lt;endl;
        return 1;
    }
*/
    cout&lt;&lt;&quot;get text: \n&quot;;
    for(int i=0;i&lt;len;i++)
    {
       let=getchar();
       if(let!=&#039;\n&#039;)
       {
            sss[i]=let;
       }
       else
       {
            sss[i]=&#039;\0&#039;;
            break;
       }
   }
   cout&lt;&lt;&quot;str=&quot;&lt;&lt;sss&lt;&lt;&quot;;&quot;&lt;&lt;endl;
   return 1;
}</code></pre></div><p>Примитив. Но если раскомментировать верхние строки, то getchar просто игнорируется. Пробовал и getline, и cin.getline-не-а! не работает. Как будто вообще ничего там не написано. В чем дело, может кто-то подсказать?<br />P.S. система-Ubuntu 9.10, компилятор g++. Хотя, думаю, это не важно</p>]]></description>
			<author><![CDATA[null@example.com (mokynis)]]></author>
			<pubDate>Thu, 03 May 2012 04:58:27 +0000</pubDate>
			<guid>https://linuxforum.ru/viewtopic.php?pid=272109#p272109</guid>
		</item>
	</channel>
</rss>
