<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[Linux Forum &mdash; не дружат cin и getchar]]></title>
	<link rel="self" href="https://linuxforum.ru/extern.php?action=feed&amp;tid=21989&amp;type=atom" />
	<updated>2012-05-04T05:47:59Z</updated>
	<generator>PunBB</generator>
	<id>https://linuxforum.ru/viewtopic.php?id=21989</id>
		<entry>
			<title type="html"><![CDATA[Re: не дружат cin и getchar]]></title>
			<link rel="alternate" href="https://linuxforum.ru/viewtopic.php?pid=272337#p272337" />
			<content type="html"><![CDATA[<p>огромное спасибо! как только дали направление, куда копать, сразу нашел кучу информации в интернете на эту тему</p>]]></content>
			<author>
				<name><![CDATA[mokynis]]></name>
				<uri>https://linuxforum.ru/profile.php?id=9040</uri>
			</author>
			<updated>2012-05-04T05:47:59Z</updated>
			<id>https://linuxforum.ru/viewtopic.php?pid=272337#p272337</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: не дружат cin и getchar]]></title>
			<link rel="alternate" href="https://linuxforum.ru/viewtopic.php?pid=272115#p272115" />
			<content type="html"><![CDATA[<p>после чтения цифры в буфере остаётся &#039;\n&#039;, который читает getchar() поэтому цикл сразу заканчивается.</p><p>ЗЫ: лучше не смешивать методы ввода си и с++. см. ifstream::get()</p>]]></content>
			<author>
				<name><![CDATA[Fat-Zer]]></name>
				<uri>https://linuxforum.ru/profile.php?id=11911</uri>
			</author>
			<updated>2012-05-03T05:40:47Z</updated>
			<id>https://linuxforum.ru/viewtopic.php?pid=272115#p272115</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[не дружат cin и getchar]]></title>
			<link rel="alternate" href="https://linuxforum.ru/viewtopic.php?pid=272109#p272109" />
			<content type="html"><![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>]]></content>
			<author>
				<name><![CDATA[mokynis]]></name>
				<uri>https://linuxforum.ru/profile.php?id=9040</uri>
			</author>
			<updated>2012-05-03T04:58:27Z</updated>
			<id>https://linuxforum.ru/viewtopic.php?pid=272109#p272109</id>
		</entry>
</feed>
