<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	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/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Revolves &#187; C++</title>
	<atom:link href="http://www.revolves.net/category/programming/c/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.revolves.net</link>
	<description>Innovation</description>
	<lastBuildDate>Wed, 05 May 2010 14:30:05 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Taking User Input Containing Spaces</title>
		<link>http://www.revolves.net/2008/11/30/taking-user-input-containing-spaces/</link>
		<comments>http://www.revolves.net/2008/11/30/taking-user-input-containing-spaces/#comments</comments>
		<pubDate>Sun, 30 Nov 2008 11:21:33 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[C++]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.revolves.net/?p=6</guid>
		<description><![CDATA[In c++, many a times, you&#8217;d want to take a string as an input. But the default cin statement cannot accept spaces, i.e. it terminates the input when it encounters a space. For eg, if you input &#8216;Hello World&#8217;, only &#8216;Hello&#8217; would be stored and rest all discarded. To overcome this, we have a function [...]]]></description>
			<content:encoded><![CDATA[<p>In c++, many a times, you&#8217;d want to take a string as an input. But the default cin statement cannot accept spaces, i.e. it terminates the input when it encounters a space. For eg, if you input &#8216;Hello World&#8217;, only &#8216;Hello&#8217; would be stored and rest all discarded. To overcome this, we have a function called cin.getline().<br />
<span id="more-6"></span></p>
<pre class="brush: cpp;">#include &lt;iostream&gt;

using namespace std;

int main()
{
    char stn[20];
    cin.getline(stn,20);
    cout&lt;&lt;stn;
    system(&quot;PAUSE&quot;);
    return 0;
}</pre>
<p>The cin.getline() function accepts two parameters, one is the variable where the input would be stored, and second is the maximum input length.</p>
<p>Lets dissect the above code,</p>
<ul>
<li>First, we declare a variable stn to store a string of maximum length 20.</li>
<li>We use the cin.getline() function, with the first parameter as our declared variable stn and second parameter as the maximum length that stn can hold, i.e 20.</li>
<li>Remember, for example if you specify the length as 5, only a maximum of 4 characters would be taken as input from the user, even if he exceeds this limit. This is because the 5th place is used to store the null terminator.</li>
</ul>
<p>Thus, the function is quite similar to the standard cin function, only that it even allows for spaces.</p>
<p>Have any suggestions or anything to say? Write a comment below!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.revolves.net/2008/11/30/taking-user-input-containing-spaces/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

<!-- Dynamic Page Served (once) in 0.219 seconds -->
