<?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: 6.6 &#8212; C-style strings</title>
	<atom:link href="http://www.learncpp.com/cpp-tutorial/66-c-style-strings/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.learncpp.com/cpp-tutorial/66-c-style-strings/</link>
	<description></description>
	<lastBuildDate>Thu, 09 Sep 2010 12:59:21 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: DaBlackIce</title>
		<link>http://www.learncpp.com/cpp-tutorial/66-c-style-strings/comment-page-1/#comment-89000</link>
		<dc:creator>DaBlackIce</dc:creator>
		<pubDate>Sat, 24 Jul 2010 07:02:40 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/66-c-style-strings/#comment-89000</guid>
		<description>Oh by the way..in the PrintInfo function, beside full name, age, etc. it should be t for tab...not t only and nNumberOfFamilyMembers.length() in the main function :)</description>
		<content:encoded><![CDATA[<p>Oh by the way..in the PrintInfo function, beside full name, age, etc. it should be t for tab&#8230;not t only and nNumberOfFamilyMembers.length() in the main function :)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: DaBlackIce</title>
		<link>http://www.learncpp.com/cpp-tutorial/66-c-style-strings/comment-page-1/#comment-88999</link>
		<dc:creator>DaBlackIce</dc:creator>
		<pubDate>Sat, 24 Jul 2010 06:49:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/66-c-style-strings/#comment-88999</guid>
		<description>I kind of found out what was wrong. Apparently it&#039;s not the do while loop.
&lt;pre&gt;
#include &quot;stdafx.h&quot;
#include &lt;iostream&gt;
#include &lt;string&gt;

using namespace std;

struct nPersonalInfo
{
	string strFullName;
	unsigned short nAge;
	string strBirthday;
	float fHeight;
	unsigned short nWeight;
};

void  PrintInfo(string strFullName, unsigned short nAge, string strBirthday,
	float fHeight, unsigned short nWeight)
{
	cout &lt;&lt; strFullName &lt;&lt; &quot;&#039;s information.&quot;&lt;&lt; endl;
	cout &lt;&lt; endl;
	
	cout &lt;&lt; &quot;Full Name:t&quot; &lt;&lt; strFullName &lt;&lt; endl;
	cout &lt;&lt; &quot;Age:tt&quot; &lt;&lt; nAge &lt;&lt; endl;
	cout &lt;&lt; &quot;Birthday:t&quot; &lt;&lt; strBirthday &lt;&lt; endl;
	cout &lt;&lt; &quot;Height:tt&quot; &lt;&lt; fHeight &lt;&lt; &quot; meters tall&quot; &lt;&lt; endl;
	cout &lt;&lt; &quot;Weight:tt&quot; &lt;&lt; nWeight &lt;&lt; &quot; lb&quot; &lt;&lt; endl;
	cout &lt;&lt; endl;
}

void AskUserInfo()
{
	cout &lt;&lt; &quot;Input your personal information.&quot; &lt;&lt; endl;
	cout &lt;&lt; endl;

	nPersonalInfo sMember;

	cout &lt;&lt; &quot;What&#039;s your full name? &quot;;
	getline(cin,sMember.strFullName);

	cout &lt;&lt; &quot;How old are you? &quot;;
	cin &gt;&gt; sMember.nAge;

	cout &lt;&lt; &quot;When were you born? (mm/dd/yy)&quot; &lt;&lt; endl;
	cin&gt;&gt; sMember.strBirthday;

	cout &lt;&lt; &quot;What is your height in meters? &quot;;
	cin &gt;&gt; sMember.fHeight;
	
	cout &lt;&lt; &quot;What is your weight in pounds? &quot;;
	cin &gt;&gt; sMember.nWeight;
	cout &lt;&lt; endl;

	PrintInfo(sMember.strFullName, sMember.nAge, sMember.strBirthday,
		sMember.fHeight, sMember.nWeight);


	cout &lt;&lt; endl;
}

int main ()
{	
	cout &lt;&lt; &quot;How many people are in your family? &quot;;
	int nNumberOfFamilyMembers;
	cin &gt;&gt; nNumberOfFamilyMembers;
	cout &lt;&lt; &quot;You have &quot; &lt;&lt; nNumberOfFamilyMembers &lt;&lt; &quot; family members.&quot; &lt;&lt; endl;

	AskUserInfo();
	for (int iii = 0; iii &lt; nNumberOfFamilyMembers; iii++)
		//AskFamilyInfo(); I won&#039;t include this function to make it short...
	return 0;
}
&lt;!--formatted--&gt;&lt;/pre&gt;
If you run this program after putting in the amount of family members, it skips the question &quot;What is your full name?&quot; 
 
But if I change:
&lt;pre&gt;cin &gt;&gt; nNumberOfFamilyMembers; &lt;!--formatted--&gt;&lt;/pre&gt;
 to: &lt;pre&gt;getline(cin, nNumberOfFamilyMembers);&lt;/pre&gt; and use nNumberOfFamilyMembers as a string instead, everything works fine. But still....I wanted to do it this way. And even so, in the loop I have to change &lt;pre&gt;nNumberOfFamilyMembers&lt;/pre&gt; to &lt;pre&gt;nNumberOfFamilyMembers.length&lt;/pre&gt; since it would be a string now. 

Anything I can do about it?</description>
		<content:encoded><![CDATA[<p>I kind of found out what was wrong. Apparently it&#8217;s not the do while loop.</p>
<pre>
#include &quot;stdafx.h&quot;
#include &lt;iostream&gt;
#include &lt;string&gt;

using namespace std;

struct nPersonalInfo
{
	string strFullName;
	unsigned short nAge;
	string strBirthday;
	float fHeight;
	unsigned short nWeight;
};

void  PrintInfo(string strFullName, unsigned short nAge, string strBirthday,
	float fHeight, unsigned short nWeight)
{
	cout &lt;&lt; strFullName &lt;&lt; &quot;&#39;s information.&quot;&lt;&lt; endl;
	cout &lt;&lt; endl;

	cout &lt;&lt; &quot;Full Name:t&quot; &lt;&lt; strFullName &lt;&lt; endl;
	cout &lt;&lt; &quot;Age:tt&quot; &lt;&lt; nAge &lt;&lt; endl;
	cout &lt;&lt; &quot;Birthday:t&quot; &lt;&lt; strBirthday &lt;&lt; endl;
	cout &lt;&lt; &quot;Height:tt&quot; &lt;&lt; fHeight &lt;&lt; &quot; meters tall&quot; &lt;&lt; endl;
	cout &lt;&lt; &quot;Weight:tt&quot; &lt;&lt; nWeight &lt;&lt; &quot; lb&quot; &lt;&lt; endl;
	cout &lt;&lt; endl;
}

void AskUserInfo()
{
	cout &lt;&lt; &quot;Input your personal information.&quot; &lt;&lt; endl;
	cout &lt;&lt; endl;

	nPersonalInfo sMember;

	cout &lt;&lt; &quot;What&#39;s your full name? &quot;;
	getline(cin,sMember.strFullName);

	cout &lt;&lt; &quot;How old are you? &quot;;
	cin &gt;&gt; sMember.nAge;

	cout &lt;&lt; &quot;When were you born? (mm/dd/yy)&quot; &lt;&lt; endl;
	cin&gt;&gt; sMember.strBirthday;

	cout &lt;&lt; &quot;What is your height in meters? &quot;;
	cin &gt;&gt; sMember.fHeight;

	cout &lt;&lt; &quot;What is your weight in pounds? &quot;;
	cin &gt;&gt; sMember.nWeight;
	cout &lt;&lt; endl;

	PrintInfo(sMember.strFullName, sMember.nAge, sMember.strBirthday,
		sMember.fHeight, sMember.nWeight);

	cout &lt;&lt; endl;
}

int main ()
{
	cout &lt;&lt; &quot;How many people are in your family? &quot;;
	int nNumberOfFamilyMembers;
	cin &gt;&gt; nNumberOfFamilyMembers;
	cout &lt;&lt; &quot;You have &quot; &lt;&lt; nNumberOfFamilyMembers &lt;&lt; &quot; family members.&quot; &lt;&lt; endl;

	AskUserInfo();
	for (int iii = 0; iii &lt; nNumberOfFamilyMembers; iii++)
		//AskFamilyInfo(); I won&#39;t include this function to make it short...
	return 0;
}
<!--formatted--></pre>
<p>If you run this program after putting in the amount of family members, it skips the question &#8220;What is your full name?&#8221; </p>
<p>But if I change:</p>
<pre>cin &gt;&gt; nNumberOfFamilyMembers; <!--formatted--></pre>
<p> to:
<pre>getline(cin, nNumberOfFamilyMembers);</pre>
<p> and use nNumberOfFamilyMembers as a string instead, everything works fine. But still&#8230;.I wanted to do it this way. And even so, in the loop I have to change
<pre>nNumberOfFamilyMembers</pre>
<p> to
<pre>nNumberOfFamilyMembers.length</pre>
<p> since it would be a string now. </p>
<p>Anything I can do about it?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Chad</title>
		<link>http://www.learncpp.com/cpp-tutorial/66-c-style-strings/comment-page-1/#comment-87559</link>
		<dc:creator>Chad</dc:creator>
		<pubDate>Thu, 01 Jul 2010 14:07:13 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/66-c-style-strings/#comment-87559</guid>
		<description>Can you post your whole program, please?</description>
		<content:encoded><![CDATA[<p>Can you post your whole program, please?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: DaBlackIce</title>
		<link>http://www.learncpp.com/cpp-tutorial/66-c-style-strings/comment-page-1/#comment-86596</link>
		<dc:creator>DaBlackIce</dc:creator>
		<pubDate>Wed, 16 Jun 2010 07:41:22 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/66-c-style-strings/#comment-86596</guid>
		<description>I&#039;ve had this problem recently...

Every time I use a do while loop and I use eg.: &lt;pre&gt; string strWhateverString;
getline(cin, strWhateverString);&lt;/pre&gt;, the compiler doesn&#039;t wait for any input and skips to the next statements. What would be the problem? If you already answered this question I&#039;m sorry...thank you in advance :)! BTW GREAT TUTORIAL...IT HAS BEEN A LOT OF HELP!</description>
		<content:encoded><![CDATA[<p>I&#8217;ve had this problem recently&#8230;</p>
<p>Every time I use a do while loop and I use eg.:
<pre> string strWhateverString;
getline(cin, strWhateverString);</pre>
<p>, the compiler doesn&#8217;t wait for any input and skips to the next statements. What would be the problem? If you already answered this question I&#8217;m sorry&#8230;thank you in advance :)! BTW GREAT TUTORIAL&#8230;IT HAS BEEN A LOT OF HELP!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: smitha</title>
		<link>http://www.learncpp.com/cpp-tutorial/66-c-style-strings/comment-page-1/#comment-79393</link>
		<dc:creator>smitha</dc:creator>
		<pubDate>Mon, 01 Mar 2010 06:17:48 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/66-c-style-strings/#comment-79393</guid>
		<description>This is a question regarding passing strings as parameters. When I pass a string constant as a parameter to a function and if I do a gets on the same variable, should it not overwrite the string? An older version of Turbo C++ does not give an error but DevC++ shows a runtime error during gets()
for example&lt;pre&gt;
#include &lt;iostream.h&gt;
#include &lt;stdio.h&gt;
#include &lt;string.h&gt;
void Display (char *str)
{
   gets(str);
   puts(str);

}
int main ()
{       
	Display(&quot;xyzxyz&quot;);
	system(&quot;pause&quot;);
}
&lt;/pre&gt;
assuming that the user enters abcabc, shouldnt str have the value abcabc, instead it runs into memory problems...though turboc++ works just fine.</description>
		<content:encoded><![CDATA[<p>This is a question regarding passing strings as parameters. When I pass a string constant as a parameter to a function and if I do a gets on the same variable, should it not overwrite the string? An older version of Turbo C++ does not give an error but DevC++ shows a runtime error during gets()<br />
for example
<pre>
#include &lt;iostream.h&gt;
#include &lt;stdio.h&gt;
#include &lt;string.h&gt;
void Display (char *str)
{
   gets(str);
   puts(str);

}
int main ()
{
	Display(&quot;xyzxyz&quot;);
	system(&quot;pause&quot;);
}
</pre>
<p>assuming that the user enters abcabc, shouldnt str have the value abcabc, instead it runs into memory problems&#8230;though turboc++ works just fine.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Rob</title>
		<link>http://www.learncpp.com/cpp-tutorial/66-c-style-strings/comment-page-1/#comment-78102</link>
		<dc:creator>Rob</dc:creator>
		<pubDate>Tue, 09 Feb 2010 15:27:30 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/66-c-style-strings/#comment-78102</guid>
		<description>&lt;pre&gt;
char szString[255];
cin.getline(szString, 255);
cout &lt;&lt; &quot;You entered: &quot; &lt;&lt; szString &lt;&lt; endl;
&lt;/pre&gt;

Won&#039;t this example over write the null terminator?</description>
		<content:encoded><![CDATA[<pre>
char szString[255];
cin.getline(szString, 255);
cout &lt;&lt; &quot;You entered: &quot; &lt;&lt; szString &lt;&lt; endl;
</pre>
<p>Won&#8217;t this example over write the null terminator?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Allan</title>
		<link>http://www.learncpp.com/cpp-tutorial/66-c-style-strings/comment-page-1/#comment-70886</link>
		<dc:creator>Allan</dc:creator>
		<pubDate>Fri, 23 Oct 2009 12:22:32 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/66-c-style-strings/#comment-70886</guid>
		<description>How about something on working with strings?
I need to add two strings together to create one longer string.

Also when comparing strings can I just ask if string1==string2 or is there a strcompare function?

I&#039;m a newbie writing my first program and referencing your site.

Thanks,
Al</description>
		<content:encoded><![CDATA[<p>How about something on working with strings?<br />
I need to add two strings together to create one longer string.</p>
<p>Also when comparing strings can I just ask if string1==string2 or is there a strcompare function?</p>
<p>I&#8217;m a newbie writing my first program and referencing your site.</p>
<p>Thanks,<br />
Al</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: jeremy</title>
		<link>http://www.learncpp.com/cpp-tutorial/66-c-style-strings/comment-page-1/#comment-68546</link>
		<dc:creator>jeremy</dc:creator>
		<pubDate>Fri, 18 Sep 2009 04:33:39 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/66-c-style-strings/#comment-68546</guid>
		<description>In Code::Blocks, 
Go To &quot;Settings&quot; &gt; &quot;Editor&quot; &gt; &quot;Syntax highlighting&quot; &gt; &quot;Keywords...&quot; 
Add &quot;string&quot; to the list. 
It will now appear as a keyword like &quot;int&quot;.</description>
		<content:encoded><![CDATA[<p>In Code::Blocks,<br />
Go To &#8220;Settings&#8221; &gt; &#8220;Editor&#8221; &gt; &#8220;Syntax highlighting&#8221; &gt; &#8220;Keywords&#8230;&#8221;<br />
Add &#8220;string&#8221; to the list.<br />
It will now appear as a keyword like &#8220;int&#8221;.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Learn C++ - &#187; 17.1 &#8212; std::string and std::wstring</title>
		<link>http://www.learncpp.com/cpp-tutorial/66-c-style-strings/comment-page-1/#comment-68208</link>
		<dc:creator>Learn C++ - &#187; 17.1 &#8212; std::string and std::wstring</dc:creator>
		<pubDate>Sat, 12 Sep 2009 22:43:37 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/66-c-style-strings/#comment-68208</guid>
		<description>[...] a previous lesson, we covered C-style strings, which using char arrays to store a string of characters. If you&#8217;ve tried to do anything with [...]</description>
		<content:encoded><![CDATA[<p>[...] a previous lesson, we covered C-style strings, which using char arrays to store a string of characters. If you&#8217;ve tried to do anything with [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Frank</title>
		<link>http://www.learncpp.com/cpp-tutorial/66-c-style-strings/comment-page-1/#comment-63973</link>
		<dc:creator>Frank</dc:creator>
		<pubDate>Thu, 09 Jul 2009 04:12:56 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/66-c-style-strings/#comment-63973</guid>
		<description>I added to your example program just for giggles and i thought i would share my minor extension. by the way alex this is a great tutorial and i am learning a lot but i am still struggling a bit with writing a coherent program. perhaps if there were a few example programs (3-4 with explainations of what each part does ect.) at the end of each chapter just for us to copy? this would help me out tremendously to grasp what you are telling us in the sections. 

here is the code:

&lt;pre&gt; #include &lt;cstdlib&gt;
#include &lt;iostream&gt;
#include &lt;string&gt;

int main()
{
    using namespace std;
          cout &lt;&lt; &quot;Enter your name: &quot;;
          string strString;
          cin &gt;&gt; strString;
          cout &lt;&lt; &quot;Hello, &quot; &lt;&lt; strString &lt;&lt; &quot;!&quot; &lt;&lt; endl;
          cout &lt;&lt; &quot;Your name has &quot; &lt;&lt;strString.length() &lt;&lt; 
          &quot; characters in it&quot; &lt;&lt; endl;
          cout &lt;&lt; &quot;The 2nd character is: &quot; &lt;&lt; strString[1] &lt;&lt; endl;
          strString = &quot;Dave&quot;;
          cout &lt;&lt; &quot;your name is now &quot; &lt;&lt; strString &lt;&lt; endl;
          cout &lt;&lt; &quot;Hello &quot; &lt;&lt; strString &lt;&lt; &quot;, Would you like to hear me sing a song?&quot; &lt;&lt;endl;
          string strAnswer;
          cin &gt;&gt; strAnswer;
              if ( strAnswer == &quot;yes&quot; )
                 cout &lt;&lt; &quot; \n Daisy, Daisy give me your answer do. \n Im half crazy all for the love of you \n \n&quot;;
                 else if (strAnswer == &quot;no&quot;)
                      cout &lt;&lt; &quot;Ok, Goodbye &quot; &lt;&lt; strString &lt;&lt; endl;
                      else 
                      cout &lt;&lt; &quot;I dont understand you &quot; &lt;&lt; strString &lt;&lt; endl;         
system (&quot;PAUSE&quot;);

return 0;
&lt;/pre&gt;</description>
		<content:encoded><![CDATA[<p>I added to your example program just for giggles and i thought i would share my minor extension. by the way alex this is a great tutorial and i am learning a lot but i am still struggling a bit with writing a coherent program. perhaps if there were a few example programs (3-4 with explainations of what each part does ect.) at the end of each chapter just for us to copy? this would help me out tremendously to grasp what you are telling us in the sections. </p>
<p>here is the code:</p>
<pre> #include &lt;cstdlib&gt;
#include &lt;iostream&gt;
#include &lt;string&gt;

int main()
{
    using namespace std;
          cout &lt;&lt; &quot;Enter your name: &quot;;
          string strString;
          cin &gt;&gt; strString;
          cout &lt;&lt; &quot;Hello, &quot; &lt;&lt; strString &lt;&lt; &quot;!&quot; &lt;&lt; endl;
          cout &lt;&lt; &quot;Your name has &quot; &lt;&lt;strString.length() &lt;&lt;
          &quot; characters in it&quot; &lt;&lt; endl;
          cout &lt;&lt; &quot;The 2nd character is: &quot; &lt;&lt; strString[1] &lt;&lt; endl;
          strString = &quot;Dave&quot;;
          cout &lt;&lt; &quot;your name is now &quot; &lt;&lt; strString &lt;&lt; endl;
          cout &lt;&lt; &quot;Hello &quot; &lt;&lt; strString &lt;&lt; &quot;, Would you like to hear me sing a song?&quot; &lt;&lt;endl;
          string strAnswer;
          cin &gt;&gt; strAnswer;
              if ( strAnswer == &quot;yes&quot; )
                 cout &lt;&lt; &quot; \n Daisy, Daisy give me your answer do. \n Im half crazy all for the love of you \n \n&quot;;
                 else if (strAnswer == &quot;no&quot;)
                      cout &lt;&lt; &quot;Ok, Goodbye &quot; &lt;&lt; strString &lt;&lt; endl;
                      else
                      cout &lt;&lt; &quot;I dont understand you &quot; &lt;&lt; strString &lt;&lt; endl;
system (&quot;PAUSE&quot;);

return 0;
</pre>
]]></content:encoded>
	</item>
</channel>
</rss>
