<?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>Ruelicke.net &#187; C Sharp</title>
	<atom:link href="http://www.ruelicke.net/tag/c-sharp/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.ruelicke.net</link>
	<description>...when coding passion, gaming addiction, Internet surfing syndrome and the real life collide...</description>
	<lastBuildDate>Mon, 05 Apr 2010 17:11:25 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>C#/C++ &#8211; Hello World!</title>
		<link>http://www.ruelicke.net/2008/01/09/c-sharp-c-plus-plus-hello-world/</link>
		<comments>http://www.ruelicke.net/2008/01/09/c-sharp-c-plus-plus-hello-world/#comments</comments>
		<pubDate>Wed, 09 Jan 2008 07:00:51 +0000</pubDate>
		<dc:creator>Marco</dc:creator>
				<category><![CDATA[C#/C++]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[C]]></category>
		<category><![CDATA[C Plus Plus]]></category>
		<category><![CDATA[C Sharp]]></category>
		<category><![CDATA[Coding]]></category>

		<guid isPermaLink="false">http://www.ruelicke.net/2008/01/c-sharp-c-plus-plus-hello-world/</guid>
		<description><![CDATA[As I have the fortune to learn C#/C++ at school I thought it is a good idea to share what I learned and what I&#8217;m learning. Additionally it helps me to repeat what I learned and I can make sure that I really understood it.
Here we go:
Hello World
At first we need a program which allows [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.ruelicke.net/wp-content/themes/ruelicke/images/icon-c-sharp-c-plus-plus.png" alt="C#/C++" title="C#/C++" class="alignleft" /><span class="c_letter">A</span>s I have the fortune to learn C#/C++ at school I thought it is a good idea to share what I learned and what I&#8217;m learning. Additionally it helps me to repeat what I learned and I can make sure that I really understood it.</p>
<p><span class="c_letter">H</span>ere we go:</p>
<h3>Hello World</h3>
<p><span class="c_letter">A</span>t first we need a program which allows us to write and compile C#/C++ code. We are using the <a href="http://www.codegear.com/products/cppbuilder">Borland C++ Builder</a> but as I&#8217;m a fan of open-source programs I&#8217;m training my knowledge using the <a href="http://www.bloodshed.net/devcpp.html">Bloodshed Dev-C++</a> program unless I&#8217;m forced to use Borland.</p>
<p><span class="c_letter">N</span>ow let&#8217;s have a look at our first program.<span id="more-159"></span></p>
<h3>The Code</h3>
<p><code style="background-color:#FFF;color:#000;display:block;padding-left:0.2em;"><br />
<span style="background-color:#FFF;color:#008000;">#pragma hdrstop</span><br />
<span style="background-color:#FFF;color:#008000;">#include &lt;conio.h&gt;</span><br />
<span style="background-color:#FFF;color:#008000;">#include &lt;iostream.h&gt;</span><br />
<span style="background-color:#FFF;color:#5E81BC;font-style:italic;">//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -</span><br />
<span style="background-color:#FFF;color:#008000;">#pragma argsused</span><br />
<span style="font-weight:700;">int</span> main(<span style="font-weight:700;">int</span> argc, <span style="font-weight:700;">char*</span> argv[])<br />
{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cout &lt;&lt; <span style="background-color:#FFF;color:#F00;">"Hello world!"</span>;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;getch();<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="font-weight:700;">return</span> <span style="background-color:#FFF;color:#800080;">0</span>;<br />
}<br />
&nbsp;<br />
</code><br />
<span class="c_letter">C</span>opy and paste the code into your C++ program, compile and execute it. A console window should open displaying &#8220;Hello world!&#8221;. Press any key to close the window again.</p>
<p><span class="c_letter">N</span>ow as your program is working, let&#8217;s have a look at the code itself.</p>
<h3>Detailed Explanation</h3>
<p><code style="background-color:#FFF;color:#000;display:block;padding-left:0.2em;"><span style="background-color:#FFF;color:#008000;">#pragma hdrstop</span><br />
[...]<br />
<span style="background-color:#FFF;color:#008000;">#pragma argsused</span><br />
</code><br />
These two lines hide possible error warnings in Borland. The program will even work if you leave them out.</p>
<p><code style="background-color:#FFF;color:#000;display:block;padding-left:0.2em;"><span style="background-color:#FFF;color:#008000;">#include &lt;conio.h&gt;</span><br />
<span style="background-color:#FFF;color:#008000;">#include &lt;iostream.h&gt;</span><br />
</code><br />
<strong>&#8220;conio.h&#8221;</strong> is a library required to create a program which runs in a console window. This &#8220;abbreviation&#8221; means <strong>CON</strong>sole<strong>I</strong>nput<strong>O</strong>utput.</p>
<p><strong>&#8220;iostream.h&#8221;</strong> is a library required to allow the program to output streamed content, also it allows streamed input. This &#8220;abbreviation&#8221; means <strong>I</strong>nput<strong>O</strong>utput<strong>STREAM</strong>.</p>
<p><code style="background-color:#FFF;color:#000;display:block;padding-left:0.2em;"><span style="background-color:#FFF;color:#5E81BC;font-style:italic;">//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -</span><br />
</code><br />
The <strong>&#8220;//&#8221;</strong> allows you to add a single line comment to the code. We use the line &#8220;- &#8211; - -&#8221; to separate the includes from the actual code.</p>
<p><code style="background-color:#FFF;color:#000;display:block;padding-left:0.2em;"><span style="font-weight:700;">int</span> main(<span style="font-weight:700;">int</span> argc, <span style="font-weight:700;">char*</span> argv[])<br />
{<br />
[...]<br />
}<br />
</code><br />
This function is the main function. Inside it you have every code you need to run the program. Later you will learn to create your own functions, so I stop here only stating that this function is always the last one of the whole program. Meaning: It has to stay at the bottom of the whole code.</p>
<p>As <a href="http://www.slevi.net">Slevi</a> outlined in his comment, the &#8220;<span style="font-weight:700;">int</span> argc, <span style="font-weight:700;">char*</span> argv[])&#8221; is used to receive the arguments in case you start the exe via console e.g. &#8220;example.exe foo bar&#8221;. As this is already advanced coding I skip a more detailed description. I&#8217;ll come back to it in a later tutorial.</p>
<p><code style="background-color:#FFF;color:#000;display:block;padding-left:0.2em;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cout &lt;&lt; <span style="background-color:#FFF;color:#F00;">"Hello world!"</span>;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;getch();<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="font-weight:700;">return</span> <span style="background-color:#FFF;color:#800080;">0</span>;<br />
</code><br />
Now we look at the actual code which allows us to display &#8220;Hello world!&#8221; in the console.</p>
<p><strong>&#8220;cout&#8221;</strong> allows you to output any kind of data. In this case it is &#8220;Hello world!&#8221;, later you will also learn about other types of data..</p>
<p><strong>&#8220;&lt;&lt;&#8221;</strong> is a shift operator which moves the output to the console screen. You could say said &#8220;cout&#8221; is the screen and &#8220;Hello world!&#8221; is moved to the screen by the &#8220;&lt;&lt;&#8221;.</p>
<p><strong>&#8220;Hello world!&#8221;</strong> is a so-called string which is displayed in the console. That&#8217;s why it is required to wrap it with the quotation marks.</p>
<p><strong>&#8220;getch()&#8221;</strong> is a function which waits for any kind of user input, basically it waits that the user is pressing any key to continue. We use it here to prevent the console from closing again right after displaying our &#8220;Hello world&#8221;. For the record, this is a solution I was looking for when I tried to learn C++ on my on a couple of years ago. All other tutorials on the Internet did not have this function in the code, leading to an instantly closed console window. Hopefully this tutorial will help other beginners to avoid my problem back then.</p>
<p><strong>&#8220;return 0&#8243;</strong> informs the program that the code has been processed and the console window can be closed, after the mentioned user input. It is not possible to avoid using &#8220;getch()&#8221; and use &#8220;return 1&#8243; instead, as this one will also exit the program.</p>
<h3>Wrap Up</h3>
<p><span>N</span>ow we are finished and got our first program working, if you encounter any kind of problem, leave me a message and I&#8217;ll try to help you.</p>
<p>P.S. Feel free to play around and try different messages just for the fun of it. <img src='http://www.ruelicke.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p><ins datetime="2008-01-12T20:55:29+00:00">Update:</ins><br />
<span class="c_letter">I</span> just had to add this note about <strong>getch()</strong>:<br />
The getch() function is a C function, but since I&#8217;m writing a C#/C++ tutorial it would be more appropriate to use <strong>cin.get()</strong> instead. It does the same but is the C++ variant of the command. Either method should work and I will get back to cin.get() in one of my next tutorials to make sure that any questions about cin.get() get answered.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ruelicke.net/2008/01/09/c-sharp-c-plus-plus-hello-world/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
	</channel>
</rss>
