<?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"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: 13.2 &#8212; Input with istream</title>
	<atom:link href="http://www.learncpp.com/cpp-tutorial/132-input-with-istream/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.learncpp.com/cpp-tutorial/132-input-with-istream/</link>
	<description></description>
	<lastBuildDate>Tue, 07 Feb 2012 12:30:29 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
	<item>
		<title>By: mslade</title>
		<link>http://www.learncpp.com/cpp-tutorial/132-input-with-istream/comment-page-1/#comment-95009</link>
		<dc:creator>mslade</dc:creator>
		<pubDate>Tue, 07 Dec 2010 02:39:13 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/132-input/#comment-95009</guid>
		<description>Looks like you got spammed on this page, too:  &quot;Note that we only read&quot;.</description>
		<content:encoded><![CDATA[<p>Looks like you got spammed on this page, too:  &#8220;Note that we only read&#8221;.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ankita Panchal</title>
		<link>http://www.learncpp.com/cpp-tutorial/132-input-with-istream/comment-page-1/#comment-77767</link>
		<dc:creator>Ankita Panchal</dc:creator>
		<pubDate>Wed, 03 Feb 2010 08:04:39 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/132-input/#comment-77767</guid>
		<description>If you going to fast, I need some help. I&#039;m having some problem with the game programming. If you could email me back with some tutorial at email adress that is mention, I will appreciate it. 

Thanks, 

Ankita</description>
		<content:encoded><![CDATA[<p>If you going to fast, I need some help. I&#8217;m having some problem with the game programming. If you could email me back with some tutorial at email adress that is mention, I will appreciate it. </p>
<p>Thanks, </p>
<p>Ankita</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Javed Nazim</title>
		<link>http://www.learncpp.com/cpp-tutorial/132-input-with-istream/comment-page-1/#comment-72867</link>
		<dc:creator>Javed Nazim</dc:creator>
		<pubDate>Mon, 23 Nov 2009 21:13:57 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/132-input/#comment-72867</guid>
		<description>some code to demonstrate removing the newline character left by get
&lt;pre&gt;
#include&lt;iostream&gt;
#include&lt;conio.h&gt;
using namespace std;
int main()
{   
    char s[10];
    char ch;
    cin.get(s,10); // type abcd &lt;enter&gt;
    cout&lt;&lt;s;
    //Will leave line feed in buffer
    cin.get(ch); // removes line feed
    cout&lt;&lt;(int)ch; //will display 10 Ascii value of line feed

    cin.get(s,10); // Can read characters again
    cout&lt;&lt;s;
    getch(); // function in conio.h to read a single character w/o echoing
    return 0;
}
&lt;/pre&gt;</description>
		<content:encoded><![CDATA[<p>some code to demonstrate removing the newline character left by get</p>
<pre>
#include&lt;iostream&gt;
#include&lt;conio.h&gt;
using namespace std;
int main()
{
    char s[10];
    char ch;
    cin.get(s,10); // type abcd &lt;enter&gt;
    cout&lt;&lt;s;
    //Will leave line feed in buffer
    cin.get(ch); // removes line feed
    cout&lt;&lt;(int)ch; //will display 10 Ascii value of line feed

    cin.get(s,10); // Can read characters again
    cout&lt;&lt;s;
    getch(); // function in conio.h to read a single character w/o echoing
    return 0;
}
</pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: Alex</title>
		<link>http://www.learncpp.com/cpp-tutorial/132-input-with-istream/comment-page-1/#comment-59735</link>
		<dc:creator>Alex</dc:creator>
		<pubDate>Sat, 02 May 2009 04:08:15 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/132-input/#comment-59735</guid>
		<description>Here&#039;s what I suspect happened:
* The first getline took all your input, but only saved the first 10 chars into strBuf.  Because it could not write all of the characters you entered into the buffer, it set some sort of error state.  I talk about this more in &lt;a href=&quot;http://www.learncpp.com/cpp-tutorial/135-stream-states-and-input-validation/&quot; rel=&quot;nofollow&quot;&gt;lesson 13.5 -- stream states and input validation&lt;/a&gt;
* Because the error state was set, the other input lines were ignored.

You can probably fix this by clearing any error state after the each getline().

A C++ program can have lots of errors.  Having multiple errors in the same place can make identifying them very difficult.</description>
		<content:encoded><![CDATA[<p>Here&#8217;s what I suspect happened:<br />
* The first getline took all your input, but only saved the first 10 chars into strBuf.  Because it could not write all of the characters you entered into the buffer, it set some sort of error state.  I talk about this more in <a href="http://www.learncpp.com/cpp-tutorial/135-stream-states-and-input-validation/" rel="nofollow">lesson 13.5 &#8212; stream states and input validation</a><br />
* Because the error state was set, the other input lines were ignored.</p>
<p>You can probably fix this by clearing any error state after the each getline().</p>
<p>A C++ program can have lots of errors.  Having multiple errors in the same place can make identifying them very difficult.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: absk007</title>
		<link>http://www.learncpp.com/cpp-tutorial/132-input-with-istream/comment-page-1/#comment-52182</link>
		<dc:creator>absk007</dc:creator>
		<pubDate>Sat, 21 Mar 2009 20:40:42 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/132-input/#comment-52182</guid>
		<description>&lt;pre&gt;
#include &lt;iostream&gt;
using namespace std;
int main()
{
    char strBuf[11];
    // Read up to 10 characters
    cin.getline(strBuf, 11);
    cout &lt;&lt; strBuf &lt;&lt; endl;

    // Read up to 10 more characters
    cin.getline(strBuf, 11);
    cout &lt;&lt; strBuf &lt;&lt; endl;
    return 0;
}
&lt;!--formatted--&gt;&lt;/pre&gt;

The above code didn&#039;t work as expected.

When I inserted &quot;&lt;b&gt;Avishee Patterson is a very nice boy.&lt;/b&gt;&quot; for the first &lt;i&gt;getline&lt;/i&gt;, it only printed &quot;&lt;b&gt;Avishee Pa&lt;/b&gt;&quot; and two &lt;em&gt;&quot;new lines&quot;&lt;/em&gt; and exited.

What&#039;s the catch? Why didn&#039;t it work?
Is it because, I have more than 11 characters?
Is there any more feasible reason for this?


&lt;blockquote cite=&quot;Misc Question&quot;&gt;Does a C++ Program error has exactly only one reason? I mean, does a C++ error depends only on one cause?&lt;/blockquote&gt;</description>
		<content:encoded><![CDATA[<pre>
#include &lt;iostream&gt;
using namespace std;
int main()
{
    char strBuf[11];
    // Read up to 10 characters
    cin.getline(strBuf, 11);
    cout &lt;&lt; strBuf &lt;&lt; endl;

    // Read up to 10 more characters
    cin.getline(strBuf, 11);
    cout &lt;&lt; strBuf &lt;&lt; endl;
    return 0;
}
<!--formatted--></pre>
<p>The above code didn&#8217;t work as expected.</p>
<p>When I inserted &#8220;<b>Avishee Patterson is a very nice boy.</b>&#8221; for the first <i>getline</i>, it only printed &#8220;<b>Avishee Pa</b>&#8221; and two <em>&#8220;new lines&#8221;</em> and exited.</p>
<p>What&#8217;s the catch? Why didn&#8217;t it work?<br />
Is it because, I have more than 11 characters?<br />
Is there any more feasible reason for this?</p>
<blockquote cite="Misc Question"><p>Does a C++ Program error has exactly only one reason? I mean, does a C++ error depends only on one cause?</p></blockquote>
]]></content:encoded>
	</item>
	<item>
		<title>By: Unknown</title>
		<link>http://www.learncpp.com/cpp-tutorial/132-input-with-istream/comment-page-1/#comment-49506</link>
		<dc:creator>Unknown</dc:creator>
		<pubDate>Sun, 08 Mar 2009 23:49:25 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/132-input/#comment-49506</guid>
		<description>Alex

You need to tell tell the people that you need to include the header &quot;iomanip&quot; if people want to use setw(). Visual C++ 2005 express edition gives the error &quot;identifier not found :&#039;setw&#039;&quot;.

[ Thanks for the note.  I updated the example.  -Alex ]</description>
		<content:encoded><![CDATA[<p>Alex</p>
<p>You need to tell tell the people that you need to include the header &#8220;iomanip&#8221; if people want to use setw(). Visual C++ 2005 express edition gives the error &#8220;identifier not found :&#8217;setw&#8217;&#8221;.</p>
<p>[ Thanks for the note.  I updated the example.  -Alex ]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: prabodh</title>
		<link>http://www.learncpp.com/cpp-tutorial/132-input-with-istream/comment-page-1/#comment-46534</link>
		<dc:creator>prabodh</dc:creator>
		<pubDate>Mon, 23 Feb 2009 17:27:18 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/132-input/#comment-46534</guid>
		<description>please tell why simple i/o  prog. run only in dos shell?
and streams run in prog. mode [ant+r]  . .</description>
		<content:encoded><![CDATA[<p>please tell why simple i/o  prog. run only in dos shell?<br />
and streams run in prog. mode [ant+r]  . .</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Alex</title>
		<link>http://www.learncpp.com/cpp-tutorial/132-input-with-istream/comment-page-1/#comment-41938</link>
		<dc:creator>Alex</dc:creator>
		<pubDate>Fri, 06 Feb 2009 05:05:40 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/132-input/#comment-41938</guid>
		<description>get(ch) returns a result of type istream&amp;.  Since this is a reference, it is guaranteed to always be non-zero.  Consequently, &quot;while (cin.get(ch))&quot; is logically equivalent to:

&lt;pre&gt;
while (true)
  cin.get(ch);
&lt;/pre&gt;

Note that this is actually an infinite loop, and thus probably not something you&#039;d want to do in a non-sample program.</description>
		<content:encoded><![CDATA[<p>get(ch) returns a result of type istream&#038;.  Since this is a reference, it is guaranteed to always be non-zero.  Consequently, &#8220;while (cin.get(ch))&#8221; is logically equivalent to:</p>
<pre>
while (true)
  cin.get(ch);
</pre>
<p>Note that this is actually an infinite loop, and thus probably not something you&#8217;d want to do in a non-sample program.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Julie</title>
		<link>http://www.learncpp.com/cpp-tutorial/132-input-with-istream/comment-page-1/#comment-37206</link>
		<dc:creator>Julie</dc:creator>
		<pubDate>Mon, 12 Jan 2009 12:12:40 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/132-input/#comment-37206</guid>
		<description>So in &quot;while (cin.get(ch))&quot; what does &quot;cin.get(ch)&quot; do, exactly? Does it mean, as long as a character can be read in from cin AND it is successfully stored in ch?

Similarly would you please explain in detail &quot;while (cin &gt;&gt; ch)&quot; - does it mean, as long as something can be successfully read from cin and it is successfully stored in ch?

More generally, it would be a big help if you could explain things used in loop (or if) conditions which aren&#039;t straightforward expressions like i&lt;5. I find them hard to follow or understand but I couldn&#039;t find anything about those in your control flow tutorials. I know they&#039;re meant to evaluate to true or false but I&#039;m not sure how you evaluate some of those conditions, especially if they involve pointers or operators like &lt;&lt; etc.

And even more generally, may I say that your site has been very useful in explaining the basics in a way that&#039;s clear, practical and provides a solid foundation for the reader to build on and progress from. Thank you very much.</description>
		<content:encoded><![CDATA[<p>So in &#8220;while (cin.get(ch))&#8221; what does &#8220;cin.get(ch)&#8221; do, exactly? Does it mean, as long as a character can be read in from cin AND it is successfully stored in ch?</p>
<p>Similarly would you please explain in detail &#8220;while (cin &gt;&gt; ch)&#8221; &#8211; does it mean, as long as something can be successfully read from cin and it is successfully stored in ch?</p>
<p>More generally, it would be a big help if you could explain things used in loop (or if) conditions which aren&#8217;t straightforward expressions like i&lt;5. I find them hard to follow or understand but I couldn&#8217;t find anything about those in your control flow tutorials. I know they&#8217;re meant to evaluate to true or false but I&#8217;m not sure how you evaluate some of those conditions, especially if they involve pointers or operators like &lt;&lt; etc.</p>
<p>And even more generally, may I say that your site has been very useful in explaining the basics in a way that&#8217;s clear, practical and provides a solid foundation for the reader to build on and progress from. Thank you very much.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Alex</title>
		<link>http://www.learncpp.com/cpp-tutorial/132-input-with-istream/comment-page-1/#comment-35419</link>
		<dc:creator>Alex</dc:creator>
		<pubDate>Tue, 23 Dec 2008 07:08:51 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/132-input/#comment-35419</guid>
		<description>Here&#039;s what actually happens.  If the cin buffer is empty, it lets you type as many characters as you want into the buffer.  As long as there is a character in the buffer that is non-zero, the while statement succeeds and the next character is printed (and removed from the buffer).

When all the characters you typed have been printed, the buffer is empty again and it will wait for you to enter more characters into it.</description>
		<content:encoded><![CDATA[<p>Here&#8217;s what actually happens.  If the cin buffer is empty, it lets you type as many characters as you want into the buffer.  As long as there is a character in the buffer that is non-zero, the while statement succeeds and the next character is printed (and removed from the buffer).</p>
<p>When all the characters you typed have been printed, the buffer is empty again and it will wait for you to enter more characters into it.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

