<?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>Function13.net &#187; C++</title>
	<atom:link href="http://www.function13.net/tag/c/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.function13.net</link>
	<description>A blog about technology and code.</description>
	<lastBuildDate>Tue, 23 Feb 2010 07:37:41 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Conway&#8217;s Game of Life in C++</title>
		<link>http://www.function13.net/2008/08/24/conways-game-of-life-in-c/</link>
		<comments>http://www.function13.net/2008/08/24/conways-game-of-life-in-c/#comments</comments>
		<pubDate>Mon, 25 Aug 2008 00:38:51 +0000</pubDate>
		<dc:creator>lijamez</dc:creator>
				<category><![CDATA[C++]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[game of life]]></category>

		<guid isPermaLink="false">http://lijamez.wordpress.com/?p=137</guid>
		<description><![CDATA[A (rather crude) version of the Game of Life written in C++. You&#8217;ll need to compile it. View the Source]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.function13.net/wp-content/gameoflife.png"><img class="aligncenter size-full wp-image-469" title="gameoflife" src="http://www.function13.net/wp-content/gameoflife.png" alt="gameoflife" width="447" height="343" /></a></p>
<p style="text-align:center;">
<p>A (rather crude) version of the Game of Life written in C++. You&#8217;ll need to <a href="http://www.function13.net/?p=128">compile it</a>.</p>
<p><a href="http://snipt.net/lijamez/conways-game-of-life-in-c">View the Source</a></p>
<div class="shr-bookmarks shr-bookmarks-expand shr-bookmarks-spaced">
<ul class="socials">
<li class="sexy-reddit">
			<a href="" rel="nofollow" title=""></a>
		</li>
<li class="sexy-digg">
			<a href="" rel="nofollow" title=""></a>
		</li>
<li class="sexy-delicious">
			<a href="" rel="nofollow" title=""></a>
		</li>
<li class="sexy-stumbleupon">
			<a href="" rel="nofollow" title=""></a>
		</li>
<li class="sexy-facebook">
			<a href="" rel="nofollow" title=""></a>
		</li>
<li class="sexy-linkedin">
			<a href="" rel="nofollow" title=""></a>
		</li>
<li class="sexy-google">
			<a href="" rel="nofollow" title=""></a>
		</li>
<li class="sexy-slashdot">
			<a href="" rel="nofollow" title=""></a>
		</li>
<li class="sexy-blogger">
			<a href="" rel="nofollow" title=""></a>
		</li>
</ul>
<div style="clear:both;"></div>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.function13.net/2008/08/24/conways-game-of-life-in-c/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Basic Compilation of a C++ Program</title>
		<link>http://www.function13.net/2008/08/24/basic-compiling-of-a-c-program/</link>
		<comments>http://www.function13.net/2008/08/24/basic-compiling-of-a-c-program/#comments</comments>
		<pubDate>Mon, 25 Aug 2008 00:27:09 +0000</pubDate>
		<dc:creator>lijamez</dc:creator>
				<category><![CDATA[C++]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[compilation]]></category>
		<category><![CDATA[g++]]></category>

		<guid isPermaLink="false">http://lijamez.wordpress.com/?p=128</guid>
		<description><![CDATA[If you are using Mac OSX or Linux, go to the folder where your cpp file is located in the terminal. On windows, you will need to install g++. Assuming your source file is called main.app, and you want your output file to be called &#8220;hellos&#8221; then type the following: g++ -o hellos main.cpp To [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.function13.net/wp-content/compile.png"><img class="aligncenter size-full wp-image-472" title="compile" src="http://www.function13.net/wp-content/compile.png" alt="compile" width="417" height="273" /></a></p>
<p style="text-align:center;">
<p>If you are using Mac OSX or Linux, go to the folder where your cpp file is located in the terminal. On windows, you will need to install g++.</p>
<p>Assuming your source file is called main.app, and you want your output file to be called &#8220;hellos&#8221; then type the following:</p>
<pre>g++ -o hellos main.cpp</pre>
<p>To run it:</p>
<pre>./hellos</pre>
<p>Note: It is possible to compile the program without specifying the output file name but it will default to &#8220;a.out&#8221;:</p>
<pre>g++ main.cpp</pre>
<p>Additional compiler options can be found <a href="http://homepages.gac.edu/~mc38/2001J/documentation/g++.html">here</a>.</p>
<div class="shr-bookmarks shr-bookmarks-expand shr-bookmarks-spaced">
<ul class="socials">
<li class="sexy-reddit">
			<a href="" rel="nofollow" title=""></a>
		</li>
<li class="sexy-digg">
			<a href="" rel="nofollow" title=""></a>
		</li>
<li class="sexy-delicious">
			<a href="" rel="nofollow" title=""></a>
		</li>
<li class="sexy-stumbleupon">
			<a href="" rel="nofollow" title=""></a>
		</li>
<li class="sexy-facebook">
			<a href="" rel="nofollow" title=""></a>
		</li>
<li class="sexy-linkedin">
			<a href="" rel="nofollow" title=""></a>
		</li>
<li class="sexy-google">
			<a href="" rel="nofollow" title=""></a>
		</li>
<li class="sexy-slashdot">
			<a href="" rel="nofollow" title=""></a>
		</li>
<li class="sexy-blogger">
			<a href="" rel="nofollow" title=""></a>
		</li>
</ul>
<div style="clear:both;"></div>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.function13.net/2008/08/24/basic-compiling-of-a-c-program/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>From Java to C++: Similarities and Differences</title>
		<link>http://www.function13.net/2008/08/24/from-java-to-c-similarities-and-differences/</link>
		<comments>http://www.function13.net/2008/08/24/from-java-to-c-similarities-and-differences/#comments</comments>
		<pubDate>Mon, 25 Aug 2008 00:16:13 +0000</pubDate>
		<dc:creator>lijamez</dc:creator>
				<category><![CDATA[C++]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://lijamez.wordpress.com/?p=87</guid>
		<description><![CDATA[After some fiddling with XCode and C++, I finally got it compiling my Hello World. To my pleasure, the syntax in C++ is somewhat similar with Java, but there are still many differences. In Java, to start a class we use: public class fileName { } In a command line C++ program, the following lines [...]]]></description>
			<content:encoded><![CDATA[<p>After some fiddling with XCode and C++, I finally got it compiling my Hello World. To my pleasure, the syntax in C++ is somewhat similar with Java, but there are still many differences.</p>
<p><span id="more-87"></span></p>
<p>In Java, to start a class we use:</p>
<blockquote><p>public class fileName<br />
{</p>
<p>}</p></blockquote>
<p>In a command line C++ program, the following lines are needed:</p>
<blockquote><p>#include &lt;iostream&gt;<br />
using namespace std;</p></blockquote>
<p>iostream is needed for input and output, std is needed for basic functions like cout. Some online tutorials use #include &lt;iostream.h&gt; but apparently it&#8217;s deprecated.</p>
<p>The standard structure of a main method is:</p>
<blockquote><p>int main () {</p>
<p>//Neat stuff goes here<br />
return 0;</p>
<p>}</p></blockquote>
<h3>Printing</h3>
<p>To print something, use  &#8220;cout&#8221; (console output?) with the insertion operator &#8220;&lt;&lt;&#8221; like this:</p>
<blockquote><p>cout &lt;&lt; &#8220;Hellos!\n&#8221;;</p>
<p>int a = 1;<br />
int b = 2;<br />
int c = a + b;<br />
cout &lt;&lt; &#8220;Some variable: &#8221; &lt;&lt; c &lt;&lt; &#8220;\n&#8221; ; //Prints c<br />
cout &lt;&lt; &#8220;Some variable: &#8221; &lt;&lt; a+b &lt;&lt; endl ; //Prints the same as above</p></blockquote>
<p>The &#8220;\n&#8221; is needed to start a new line. This replaces System.out.println and System.out.print in Java. Alternatively, you can also use &#8220;endl&#8221; (end line).</p>
<p>The syntax for variable declarations are identical to Java with one small exception:</p>
<blockquote><p>string a = &#8220;Feed me&#8221;; //OK<br />
string a (&#8220;Feed me&#8221;); //OK, Identical to the line above.</p></blockquote>
<h3>Arrays</h3>
<p>Java:</p>
<blockquote><p>int[] myArray1 = new int[5];<br />
int[][] myArray2 = new int[5][6];</p></blockquote>
<p>C++:</p>
<blockquote><p>int myArray1 [5];<br />
int myArray2 [5][6];</p></blockquote>
<h3>Variables</h3>
<p>Now this is pretty cool. When assigning a value to a variable, we can use a literal constant, an octal (base <img src='http://www.function13.net/wp-includes/images/smilies/icon_cool.gif' alt='8)' class='wp-smiley' /> value, or a hex (base 16) value.</p>
<blockquote><p>int a = 123; //Literal constant<br />
a = 0173; //Octal (Start the variable with a 0)<br />
a = 0x7b; //Hex (Start the variable with 0x)</p></blockquote>
<p>Floating point numbers:</p>
<blockquote><p>double a = 3.141592654<br />
a = 6.02e23 //OK</p></blockquote>
<p>Constants:</p>
<blockquote><p>final int myVar = 100; //Java</p>
<p>const int myVar = 100; //C++</p></blockquote>
<h3>User Input</h3>
<p>Use cin. Here is an example.</p>
<blockquote><p>#include &lt;iostream&gt;<br />
using namespace std;</p>
<p>int main () {<br />
int i;<br />
cout &lt;&lt; &#8220;Enter a value&#8230;&#8221;;<br />
cin &gt;&gt; i;<br />
cout &lt;&lt; &#8220;The value you entered is &#8221; &lt;&lt; i;<br />
return 0;<br />
}</p></blockquote>
<p>Notice the use of the extraction operator &#8220;&gt;&gt;&#8221;. The line &#8220;cin &gt;&gt; i&#8221; takes the user input and stores it in the variable &#8220;i&#8221;. If the user enters a string instead of an integer, the program will not behave as you would expect. In Java, it will simply blow up. Also, the program will take whatever the user types up to a space, a tab, or a new line. Everything after these will be ignored unless you specifically store them in another variable. So, if a user enters a string which could possibly be composed of more than one word, it would be better to use the getline function.</p>
<p>The getline function works like this:</p>
<blockquote><p>#include &lt;iostream&gt;<br />
using namespace std;</p>
<p>int main () {<br />
string i;<br />
cout &lt;&lt; &#8220;Enter a sentence&#8230;\n&#8221;;<br />
getline (cin, i);<br />
cout &lt;&lt; &#8220;You said: &#8221; &lt;&lt; i;<br />
return 0;<br />
}</p></blockquote>
<p>And its output may look something like this:</p>
<blockquote><p>Enter a sentence&#8230;<br />
C++ Rocks!<br />
You said: C++ Rocks!</p></blockquote>
<h3>Control Structures</h3>
<p>If, while, do while, and for statements are identical to Java. <img src='http://www.function13.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<h3>Functions</h3>
<p>Because C++ has a 1-pass compiler, any additional functions (a.k.a. &#8220;methods&#8221; in Java) must be declared before the main function.</p>
<p>For example, this will work:</p>
<blockquote><p><span class="prep">#include &lt;iostream&gt;</span><br />
<span class="kw">using</span> <span class="kw">namespace</span> std;</p>
<p><span class="kw">int</span> addition (<span class="kw">int</span> a, <span class="kw">int</span> b)<br />
{<br />
<span class="kw">int</span> r;<br />
r=a+b;<br />
<span class="kw">return</span> (r);<br />
}</p>
<p><span class="kw">int</span> main ()<br />
{<br />
<span class="kw">int</span> z;<br />
z = addition (5,3);<br />
cout &lt;&lt; <span class="str">&#8220;The result is &#8220;</span> &lt;&lt; z;<br />
<span class="kw">return</span> 0;<br />
}</p></blockquote>
<p>And this will not:</p>
<blockquote><p><span class="prep">#include &lt;iostream&gt;</span><br />
<span class="kw">using</span> <span class="kw">namespace</span> std;</p>
<p><span class="kw">int</span> addition (<span class="kw">int</span> a, <span class="kw">int</span> b)<br />
{<br />
<span class="kw">int</span> r;<br />
r=a+b;<br />
<span class="kw">return</span> (r);<br />
}</p>
<p><span class="kw">int</span> main ()<br />
{<br />
<span class="kw">int</span> z;<br />
z = addition (5,3);<br />
cout &lt;&lt; <span class="str">&#8220;The result is &#8220;</span> &lt;&lt; z;<br />
<span class="kw">return</span> 0;<br />
}</p></blockquote>
<h3>Classes</h3>
<p>A piece of sample code:</p>
<blockquote><p>#include &lt;iostream&gt;<br />
using namespace std;</p>
<p>class Point {<br />
int x, y;<br />
public:<br />
Point (int, int);<br />
void setPoint(int, int);<br />
void printPoint() {<br />
cout &lt;&lt; &#8220;( &#8221; &lt;&lt; x &lt;&lt; &#8221; , &#8221; &lt;&lt; y &lt;&lt; &#8221; )&#8221; &lt;&lt; endl;<br />
}<br />
};</p>
<p>Point::Point (int a, int b) {<br />
x = a;<br />
y = b;<br />
}</p>
<p>void Point::setPoint(int a, int b) {<br />
x = a;<br />
y = b;<br />
}</p>
<p>int main() {</p>
<p>Point foo(1,2);<br />
foo.printPoint();<br />
return 0;<br />
}</p></blockquote>
<p>This piece of code has an object with a constructor, two functions, and the main method creates one instance of the object.</p>
<div class="shr-bookmarks shr-bookmarks-expand shr-bookmarks-spaced">
<ul class="socials">
<li class="sexy-reddit">
			<a href="" rel="nofollow" title=""></a>
		</li>
<li class="sexy-digg">
			<a href="" rel="nofollow" title=""></a>
		</li>
<li class="sexy-delicious">
			<a href="" rel="nofollow" title=""></a>
		</li>
<li class="sexy-stumbleupon">
			<a href="" rel="nofollow" title=""></a>
		</li>
<li class="sexy-facebook">
			<a href="" rel="nofollow" title=""></a>
		</li>
<li class="sexy-linkedin">
			<a href="" rel="nofollow" title=""></a>
		</li>
<li class="sexy-google">
			<a href="" rel="nofollow" title=""></a>
		</li>
<li class="sexy-slashdot">
			<a href="" rel="nofollow" title=""></a>
		</li>
<li class="sexy-blogger">
			<a href="" rel="nofollow" title=""></a>
		</li>
</ul>
<div style="clear:both;"></div>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.function13.net/2008/08/24/from-java-to-c-similarities-and-differences/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
