<?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.5 &#8212; Stream states and input validation</title>
	<atom:link href="http://www.learncpp.com/cpp-tutorial/135-stream-states-and-input-validation/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.learncpp.com/cpp-tutorial/135-stream-states-and-input-validation/</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: Ravi Gautam</title>
		<link>http://www.learncpp.com/cpp-tutorial/135-stream-states-and-input-validation/comment-page-1/#comment-96083</link>
		<dc:creator>Ravi Gautam</dc:creator>
		<pubDate>Tue, 27 Sep 2011 11:51:55 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/135-stream-states-and-input-validation/#comment-96083</guid>
		<description>Is it because  any sting is an array with a terminator at the end?</description>
		<content:encoded><![CDATA[<p>Is it because  any sting is an array with a terminator at the end?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ravi Gautam</title>
		<link>http://www.learncpp.com/cpp-tutorial/135-stream-states-and-input-validation/comment-page-1/#comment-96079</link>
		<dc:creator>Ravi Gautam</dc:creator>
		<pubDate>Tue, 27 Sep 2011 09:12:47 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/135-stream-states-and-input-validation/#comment-96079</guid>
		<description>Is (strUserInput[nIndex] an &#039;Array&#039; ?

If yes how can we use an array without first declaring it?</description>
		<content:encoded><![CDATA[<p>Is (strUserInput[nIndex] an &#8216;Array&#8217; ?</p>
<p>If yes how can we use an array without first declaring it?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: D.M. Ryan</title>
		<link>http://www.learncpp.com/cpp-tutorial/135-stream-states-and-input-validation/comment-page-1/#comment-91727</link>
		<dc:creator>D.M. Ryan</dc:creator>
		<pubDate>Thu, 09 Sep 2010 19:03:49 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/135-stream-states-and-input-validation/#comment-91727</guid>
		<description>The special characters are missed by isdigit, isspace and isalpha. Since those three commands are being used to screen out bad input, any of those special characters would be treated as bad input. If they&#039;re valid, then the function won&#039;t work because it won&#039;t let those special characters through. 

The only way I know how to test for them would be to make the conditionals that &quot;return false&quot; more stringent through the use of and&#039;s. For example, taking out 
&lt;pre&gt;
case &#039;#&#039;: // match a digit  
    if (!isdigit(strUserInput[nIndex]))  
        return false;  
&lt;/pre&gt;
and replacing it with an added and, like so:
&lt;pre&gt;
case &#039;#&#039;: // match a digit
    if (!isdigit(strUserInput[nIndex]) &amp;&amp; strUserInput[nIndex] != &#039;?&#039;) // note added and
        return false;
&lt;/pre&gt;
means the test conditional will not return &quot;false&quot; if a question mark is entered where a digit is supposed to be. That allows the user to substiture a question mark for a digit, but only for a digit.</description>
		<content:encoded><![CDATA[<p>The special characters are missed by isdigit, isspace and isalpha. Since those three commands are being used to screen out bad input, any of those special characters would be treated as bad input. If they&#8217;re valid, then the function won&#8217;t work because it won&#8217;t let those special characters through. </p>
<p>The only way I know how to test for them would be to make the conditionals that &#8220;return false&#8221; more stringent through the use of and&#8217;s. For example, taking out </p>
<pre>
case &#39;#&#39;: // match a digit
    if (!isdigit(strUserInput[nIndex]))
        return false;
</pre>
<p>and replacing it with an added and, like so:</p>
<pre>
case &#39;#&#39;: // match a digit
    if (!isdigit(strUserInput[nIndex]) &amp;&amp; strUserInput[nIndex] != &#39;?&#39;) // note added and
        return false;
</pre>
<p>means the test conditional will not return &#8220;false&#8221; if a question mark is entered where a digit is supposed to be. That allows the user to substiture a question mark for a digit, but only for a digit.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: bla</title>
		<link>http://www.learncpp.com/cpp-tutorial/135-stream-states-and-input-validation/comment-page-1/#comment-90918</link>
		<dc:creator>bla</dc:creator>
		<pubDate>Thu, 26 Aug 2010 15:19:15 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/135-stream-states-and-input-validation/#comment-90918</guid>
		<description>After the function that uses the template “(###) ###-####” the text says:
&quot;if #, @, _, and ? are valid characters in the user input, this function won’t work, because those symbols have been given special meanings.&quot;
I don&#039;t get why it wouldn&#039;t work... Can somebody explain this? Has the &quot;special meaning&quot; been given by the code or does it originate in C++?</description>
		<content:encoded><![CDATA[<p>After the function that uses the template “(###) ###-####” the text says:<br />
&#8220;if #, @, _, and ? are valid characters in the user input, this function won’t work, because those symbols have been given special meanings.&#8221;<br />
I don&#8217;t get why it wouldn&#8217;t work&#8230; Can somebody explain this? Has the &#8220;special meaning&#8221; been given by the code or does it originate in C++?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: C++ Tutorial and Online Ebook</title>
		<link>http://www.learncpp.com/cpp-tutorial/135-stream-states-and-input-validation/comment-page-1/#comment-87417</link>
		<dc:creator>C++ Tutorial and Online Ebook</dc:creator>
		<pubDate>Wed, 30 Jun 2010 01:01:08 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/135-stream-states-and-input-validation/#comment-87417</guid>
		<description>[...] 13.5 Stream states and input validation [...]</description>
		<content:encoded><![CDATA[<p>[...] 13.5 Stream states and input validation [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Martin</title>
		<link>http://www.learncpp.com/cpp-tutorial/135-stream-states-and-input-validation/comment-page-1/#comment-68195</link>
		<dc:creator>Martin</dc:creator>
		<pubDate>Sat, 12 Sep 2009 18:01:43 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/135-stream-states-and-input-validation/#comment-68195</guid>
		<description>Thanks a lot. 
Really good article. Except I used 
cin.ignore(std::numeric_limits::max(),&#039;\n&#039;);
instead of 
cin.ignore(1000, &#039;\n&#039;); 

I had a problem with two loops because I used clear and ignore at wrong places. So if 123abc was entered, somehow my app just kept silent until I pressed enter. Using your sample code for
&quot;2) If you don’t want this to be valid input, it is not rejected (and you have garbage in your stream).&quot;

fixed my problems and now my integer validation works reliably no matter when and how often I use it.

Thanks.</description>
		<content:encoded><![CDATA[<p>Thanks a lot.<br />
Really good article. Except I used<br />
cin.ignore(std::numeric_limits::max(),&#8217;\n&#8217;);<br />
instead of<br />
cin.ignore(1000, &#8216;\n&#8217;); </p>
<p>I had a problem with two loops because I used clear and ignore at wrong places. So if 123abc was entered, somehow my app just kept silent until I pressed enter. Using your sample code for<br />
&#8220;2) If you don’t want this to be valid input, it is not rejected (and you have garbage in your stream).&#8221;</p>
<p>fixed my problems and now my integer validation works reliably no matter when and how often I use it.</p>
<p>Thanks.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Violator</title>
		<link>http://www.learncpp.com/cpp-tutorial/135-stream-states-and-input-validation/comment-page-1/#comment-61837</link>
		<dc:creator>Violator</dc:creator>
		<pubDate>Tue, 02 Jun 2009 14:41:56 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/135-stream-states-and-input-validation/#comment-61837</guid>
		<description>And how do you filter out F1 to F12 keys?

[code]
while(i = _getch())				                           //validating input
{																
	if(i &gt; &#039;0&#039; &amp;&amp; i &lt; &#039;7&#039;)								
	break;
	cout &lt;&lt; &quot;Wrong number!&quot;; //input isn&#039;t valid
}
[/code]</description>
		<content:encoded><![CDATA[<p>And how do you filter out F1 to F12 keys?</p>
<pre class="brush: plain; title: ; notranslate">
while(i = _getch())				                           //validating input
{
	if(i &gt; '0' &amp;&amp; i &lt; '7')
	break;
	cout &lt;&lt; "Wrong number!"; //input isn't valid
}
</pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: sagar</title>
		<link>http://www.learncpp.com/cpp-tutorial/135-stream-states-and-input-validation/comment-page-1/#comment-25955</link>
		<dc:creator>sagar</dc:creator>
		<pubDate>Tue, 02 Sep 2008 13:12:14 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/135-stream-states-and-input-validation/#comment-25955</guid>
		<description>good program&#039;s.
i want some programs which give from user only digits.something like this.
if u have please send me on my e-mail.</description>
		<content:encoded><![CDATA[<p>good program&#8217;s.<br />
i want some programs which give from user only digits.something like this.<br />
if u have please send me on my e-mail.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Learn C++ - &#187; 13.4 &#8212; Stream classes for strings</title>
		<link>http://www.learncpp.com/cpp-tutorial/135-stream-states-and-input-validation/comment-page-1/#comment-14437</link>
		<dc:creator>Learn C++ - &#187; 13.4 &#8212; Stream classes for strings</dc:creator>
		<pubDate>Mon, 05 May 2008 02:33:13 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/135-stream-states-and-input-validation/#comment-14437</guid>
		<description>[...] 2007      Prev/Next Posts   &#171; 13.3 &#8212; Output with ostream and ios &#124; Home &#124; 13.5 &#8212; Stream states and input validation &#187;     Tuesday, March 18th, 2008 at 2:58 [...]</description>
		<content:encoded><![CDATA[<p>[...] 2007      Prev/Next Posts   &laquo; 13.3 &#8212; Output with ostream and ios | Home | 13.5 &#8212; Stream states and input validation &raquo;     Tuesday, March 18th, 2008 at 2:58 [...]</p>
]]></content:encoded>
	</item>
</channel>
</rss>

