<?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>Talk Binary &#187; C++ Program</title>
	<atom:link href="http://talkbinary.com/tag/c-program/feed/" rel="self" type="application/rss+xml" />
	<link>http://talkbinary.com</link>
	<description>Programming Resources, Technology, Computers</description>
	<lastBuildDate>Wed, 15 Feb 2012 16:01:31 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>C++ Hello World</title>
		<link>http://talkbinary.com/programming/c/c-hello-world/</link>
		<comments>http://talkbinary.com/programming/c/c-hello-world/#comments</comments>
		<pubDate>Sat, 24 Jul 2010 15:40:29 +0000</pubDate>
		<dc:creator>Diego</dc:creator>
				<category><![CDATA[C++]]></category>
		<category><![CDATA[Basic Structure of C++ Program]]></category>
		<category><![CDATA[C++ Hello World]]></category>
		<category><![CDATA[C++ Program]]></category>
		<category><![CDATA[hello world]]></category>

		<guid isPermaLink="false">http://talkbinary.com/?p=2867</guid>
		<description><![CDATA[Hello World in C++ The Hello World program is introduced to new programmers as its the simplest program to write in many languages (except GUIs). The Hello World program we&#8217;ll be writing in C++ will display &#8220;Hello World!&#8221; to the terminal. By now you must have your C++ programming environment set up, if not check<a class="moretag" href="http://talkbinary.com/programming/c/c-hello-world/">&#160;&#160;Full Article&#8230;</a>
]]></description>
			<content:encoded><![CDATA[<h3 id="section-1">Hello World in C++</h3>
<p>The <strong>Hello World</strong> program is introduced to new programmers as its the simplest program to write in many languages (except GUIs). The Hello World program we&#8217;ll be writing in C++ will display &#8220;Hello World!&#8221; to the terminal.</p>
<p>By now you must have your C++ programming environment set up, if not check out <a href="http://talkbinary.com/programming/c/c-installation/">C++ Installation</a>.</p>
<h3 id="section-2">Writing your first program</h3>
<p>The easiest way to learn how to program is by demonstrating a simple example. Simply compile the following code.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
</pre></td><td class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #339900;">#include &lt;iostream&gt;</span>
&nbsp;
<span style="color: #0000ff;">using</span> <span style="color: #0000ff;">namespace</span> std<span style="color: #008080;">;</span>
&nbsp;
<span style="color: #0000ff;">int</span> main<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> 
<span style="color: #008000;">&#123;</span>
&nbsp;
     <span style="color: #666666;">// Will display Hello World to the terminal</span>
     <span style="color: #0000dd;">cout</span> <span style="color: #000080;">&lt;&lt;</span> <span style="color: #FF0000;">&quot;Hello World!&quot;</span><span style="color: #008080;">;</span>
&nbsp;
     <span style="color: #0000ff;">return</span> <span style="color: #0000dd;">0</span><span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

<p><span id="more-2867"></span></p>
<h3 id="section-3">The basic structure of a C++ program</h3>
<p>So if you were successful, you should have <strong>Hello World</strong> displayed in your terminal. Below, I&#8217;ll go ahead and describe the basic structure of a C++ program. </p>
<p>The following tells the compiler to include the following library since we&#8217;ll be using some of its functionality in our program.</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #339900;">#include &lt;iostream&gt;</span></pre></div></div>

<p>We&#8217;ll save namespaces for a later tutorial as its a more advanced feature. For now, just know that functionality found in iostream is declared under a namespace <em>std</em>. This will be something that will be found in most of your programs.</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #0000ff;">using</span> <span style="color: #0000ff;">namespace</span> std<span style="color: #008080;">;</span></pre></div></div>

<p>The following is a functional declaration which we&#8217;ll describe later. The purpose of the main function is that it points to where your C++ program will start executing always. The {}&#8217;s simply encapsulate the body of our program.</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #0000ff;">int</span> main<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span></pre></div></div>

<p>The following are known as comments. They are useful as notes to the programmer and others who wish to edit the code later on. Their purpose is to describe the functionality of a certain block of code. Best practice is to have clear and concise comments to let the reader know what to expect.</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #666666;">// Will display Hello World to the terminal</span></pre></div></div>

<p>The following is known as a C++ statement as it terminated with a semicolon (;). The following <em>cout</em> statement belongs to the <em><iostream> library </em>and the <em>std namespace</em>. The <em>cout</em> statement is feeding the string &#8220;Hello World!&#8221; to standard output in which our case is usually a terminal.</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #0000dd;">cout</span> <span style="color: #000080;">&lt;&lt;</span> <span style="color: #FF0000;">&quot;Hello World!&quot;</span><span style="color: #008080;">;</span></pre></div></div>

<p>As mentioned before, our main function which expects an <em>int</em> value in return. The 0 denotes that the program terminated successfully.</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #0000ff;">return</span> <span style="color: #0000dd;">0</span><span style="color: #008080;">;</span></pre></div></div>

<h3 id="section-4">Overview of C++ program structure</h3>
<p>Described above is the most basic of C++ programs. For the next couple of tutorials, we&#8217;ll be using the following format. Make sure you understand the basic gist as its imperative you understand the structure of a C++ program.</p>
]]></content:encoded>
			<wfw:commentRss>http://talkbinary.com/programming/c/c-hello-world/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Page Caching using disk: enhanced

Served from: talkbinary.com @ 2012-05-23 08:59:57 -->
