<?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>TECHiE TALKS &#187; C++</title>
	<atom:link href="http://www.icpep.org/category/programming/c-programming/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.icpep.org</link>
	<description>Just another techie stuff</description>
	<lastBuildDate>Fri, 23 Jul 2010 04:53:01 +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>Bubble Sort and Graphics.h in Dev C++</title>
		<link>http://www.icpep.org/bubble-sort-and-graphics-h-in-dev-c/</link>
		<comments>http://www.icpep.org/bubble-sort-and-graphics-h-in-dev-c/#comments</comments>
		<pubDate>Sun, 18 Jul 2010 00:49:20 +0000</pubDate>
		<dc:creator>paparts</dc:creator>
				<category><![CDATA[C++]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.icpep.org/?p=1101</guid>
		<description><![CDATA[Lately I have been searching  this post on the net about graphics.h in dev c++ and found few resources about it .  So I decided to write how to use graphics.h in dev-c++.  I am expecting that you have already installed bloodshed dev-cpp on your machine.  Graphics.h is a header file found in borlan c [...]]]></description>
			<content:encoded><![CDATA[<p style="text-align: center;"><a href="http://www.icpep.org/wp-content/uploads/2010/07/dev-c++.jpg"><img class="size-full wp-image-1102 aligncenter" title="dev c++" src="http://www.icpep.org/wp-content/uploads/2010/07/dev-c++.jpg" alt="dev c++" width="472" height="293" /></a></p>
<p style="text-align: justify;">Lately I have been searching  this post on the net about graphics.h in dev c++ and found few resources about it .  So I decided to write how to use graphics.h in dev-c++.  I am expecting that you have already installed bloodshed dev-cpp on your machine.  Graphics.h is a header file found in borlan c but because of its late development devcpp is now the mostly used IDE and compiler in programming c++.</p>
<p style="text-align: justify;">Below are the steps on how to get graphics.h running on your machine,</p>
<ol>
<li>download <a href="icpep.org/downloads/graphics.h">graphics.h</a> and save it to the <strong>include</strong> folder where you installed dev-cpp (C:\Dev-Cpp\include)</li>
<li>Download <a title="libbgi" href="http://www.icpep.org/downloads/libbgi.a">libbgi.a</a> and save it in the <strong>lib </strong>folder where you installed dev-cpp (C:\Dev-Cpp\lib)</li>
<li>So when you have to create a program that needs the use of graphics.h  you must instruct the linker to link in certain libraries by going to <strong>projects &gt; project options &gt; parameters tab &gt; linker column </strong>copy the lines below and paste it on that column.</li>
</ol>
<pre style="padding-left: 30px;">-lbgi
-lgdi32
-lcomdlg32
-luuid
-loleaut32
-lole32</pre>
<p>By then you should be able to use graphics.h. As a sample I created this bubble sort algorithm as an example on how to use graphics.h in c++.<span id="more-1101"></span></p>
<div style="border: 2px solid #CECECE; padding: 5px; background: #F1F1F1;">
<div id="_mcePaste">#include &lt;iostream&gt;</div>
<div id="_mcePaste">#include &lt;graphics.h&gt;</div>
<p>#define PIXEL_COUNT 1000<br />
#define DELAY_TIME  1  /* in milliseconds */<br />
#define CLIP_ON     1</p>
<p>//using namespace std;</p>
<p>int main () {</p>
<p>int temp, x, toSort[300], loop, isSwapped=1;<br />
/* request autodetection */<br />
int gdriver = DETECT, gmode, errorcode;</p>
<p>/* initialize graphics and local variables */<br />
initgraph(&amp;gdriver, &amp;gmode, &#8220;&#8221;);</p>
<p>/* read result of initialization */<br />
errorcode = graphresult();</p>
<p>if (errorcode != grOk) {  /* an error occurred */</p>
<p>printf(&#8220;Graphics error: %s\n&#8221;, grapherrormsg(errorcode));<br />
printf(&#8220;Press any key to halt:&#8221;);<br />
getch();<br />
exit(1);               /* terminate with an error code */</p>
<p>}</p>
<p>/* Generate the numbers */<br />
for(x=0; x&lt;300; x++) {<br />
toSort[x] = rand() % 300 + 1;<br />
}</p>
<p>for(loop=0; (loop &lt;= 300)&amp;&amp; isSwapped == 1; loop++) {<br />
isSwapped = 0;<br />
for(x=0; x&lt;300; x++) {            if(toSort[x] &gt; toSort[x+1]) {</p>
<p>//swapping of data<br />
temp = toSort[x];<br />
toSort[x] = toSort[x+1];<br />
toSort[x+1] = temp;<br />
isSwapped = 1;</p>
<p>}<br />
std::cout &lt;&lt; loop &lt;&lt; &#8220;=&gt; &#8220;&lt;&lt; x &lt;&lt; &#8220;,&#8221; &lt;&lt; toSort[x] &lt;&lt; &#8221; &#8220;;</p>
<p>putpixel(x, toSort[x], 16776960);<br />
delay(DELAY_TIME);</p>
<p>}<br />
std::cout &lt;&lt; &#8220;\n\n&#8221;;<br />
if(isSwapped == 1) {<br />
cleardevice();<br />
}<br />
//loop++;<br />
}</p>
<p>//cout &lt;&lt; endl &lt;&lt; &#8220;\n\n\n&#8221;;<br />
std::cout &lt;&lt; &#8220;Loop Count: &#8221; &lt;&lt; loop &lt;&lt; &#8220;\n\n\n&#8221;;<br />
system(&#8220;pause&#8221;);<br />
return 0;<br />
}</p>
</div>
<p style="text-align: justify;">The program will have scattered points on the screen and will form a line as the loop iterates and at the end it will display how many loops are needed to sort the randomly generated numbers.</p>
<p style="text-align: justify;">If you have problems using the functions you can refer to this <a href="http://www.cs.colorado.edu/~main/bgi/doc/">link</a>.  I hope this helps in solving your problem about dev c++ graphics.h with the <strong>bubble sort algorithm</strong>.</p>
<p class="buymebeer"><form action="https://www.paypal.com/cgi-bin/webscr" target="paypal" method="post"><input type="hidden" name="cmd" value="_xclick" /><input type="hidden" name="business" value="allajosephcagadas@gmail.com" /><input type="hidden" name="return" value="" /><input type="hidden" name="item_name" value="Can You Buy Me a Beer? for Bubble Sort and Graphics.h in Dev C++" /><input type="hidden" name="currency_code" value="USD" /><input type="hidden" name="amount" value="" /><input type="image" src="http://www.icpep.org/wp-content/plugins/buy-me-beer/icon_beer.gif" align="left" alt="Buy Me a Beer" title="Buy Me a Beer" hspace="3" /></form><a href="https://www.paypal.com/cgi-bin/webscr?cmd=_xclick&amp;business=allajosephcagadas@gmail.com&amp;currency_code=USD&amp;amount=&amp;return=&amp;item_name=Can+You+Buy+Me+a+Beer?+for+Bubble+Sort+and+Graphics.h+in+Dev+C++" target="paypal">Did find the post very useful? Maybe you want to buy me a glass of beer!</a></p>]]></content:encoded>
			<wfw:commentRss>http://www.icpep.org/bubble-sort-and-graphics-h-in-dev-c/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Hello World in C++</title>
		<link>http://www.icpep.org/hello-world-in-c-2/</link>
		<comments>http://www.icpep.org/hello-world-in-c-2/#comments</comments>
		<pubDate>Fri, 19 Dec 2008 00:17:58 +0000</pubDate>
		<dc:creator>paparts</dc:creator>
				<category><![CDATA[C++]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.icpep.org/?p=133</guid>
		<description><![CDATA[//Printing Hellow World! #include &#60;iostream&#62; int main() { std::cout &#60;&#60; "Hello World! \n"; system("pause"); return 0; } Line begins with //, indicating that the remainder of the line is a comment. Programmers insert comments to document programs and also help people read and understand them. Comments do not cause the computer to perform any action [...]]]></description>
			<content:encoded><![CDATA[<pre style="text-align: justify;">//Printing Hellow World!
#include &lt;iostream&gt; 
int main()
   {
     std::cout &lt;&lt; "Hello World! \n";
     system("pause");
     return 0;
  }</pre>
<p style="text-align: justify;">Line begins with //, indicating that the remainder of the line is a comment. Programmers insert comments to document programs and also help people read and understand them. Comments do not cause the computer to perform any action when the program is run; they are ignored by the C++ compiler and do not cause any machine-language object code to be generated. The comment Text-printing program describes the purpose of the program. A comment beginning with // is called a single-line comment because it terminates at the end of the current line.  C++ programmers also may use C&#8217;s style in which a comment possibly containing many lines begins with the pair of characters /* and ends with */.</p>
<pre style="text-align: justify;">#include &lt;iostream&gt;  // allows program to output data to the screen</pre>
<p style="text-align: justify;">This is a preprocessor directive, which is a message to the C++ preprocessor.  Lines that begin with # are processed by the preprocessor before the program is compiled. This line notifies the preprocessor to include in the program the contents of the input/output stream header file . This file must be included for any program that outputs data to the screen or inputs data from the keyboard using C++-style stream input/output.</p>
<p><strong><em>CAUTION:</em></strong> Forgetting to include the  header file in a program that inputs data from the keyboard or outputs data to the screen causes the compiler to issue an error message, because the compiler cannot recognize references to the stream components (e.g., cout).</p>
<pre style="text-align: justify;">int main()</pre>
<p style="text-align: justify;">The parentheses after main indicate that main is a program building block called a function. C++ programs typically consist of one or more functions and classes.  Exactly one function in every program must be main.  Like our program above, it contains only one function. C++ programs begin executing at function main, even if main is not the first function in the program. The keyword int to the left of main indicates that main &#8220;returns&#8221; an integer (whole number) value.  A keyword is a word in code that is reserved by C++ for a specific use.  The left brace, {, must begin the body of every function. A corresponding right brace, }, must end each function&#8217;s body.<span id="more-133"></span></p>
<pre style="text-align: justify;">std::cout &lt;&lt; "Hello World!\n"; // display message</pre>
<p style="text-align: justify;">This instructs the computer to perform an action namely, to print the string of characters contained between the double quotation marks. A string is sometimes called a character string, a message or a string literal. We refer to characters between double quotation marks simply as strings. White-space characters in strings are not ignored by the compiler.  std::cout, the &lt;&lt; operator, the string &#8220;Hello World++!\n&#8221; and the semicolon (;), is called a statement. Every C++ statement must end with a semicolon (also known as the statement terminator). Preprocessor directives (like #include) do not end with a semicolon. Output and input in C++ are accomplished with streams of characters. Thus, when the preceding statement is executed, it sends the stream of characters Welcome to C++!\n to the standard output stream objectstd::cout which is normally &#8220;connected&#8221; to the screen.<br />
If you have noticed that we placed std:: before cout. This is required when we use names that we&#8217;ve brought into the program by the preprocessor directive #include .<script type="text/javascript"><!--</p>
<p>google_ad_client = "pub-4547412119801593";
/* c++ programming learning */
google_ad_slot = "9752287257";
google_ad_width = 200;
google_ad_height = 200;
// --></script><br />
<script src="http://pagead2.googlesyndication.com/pagead/show_ads.js" type="text/javascript"></script><br />
The &lt;&lt; operator is referred to as the stream insertion operator. When this program executes, the value to the right of the operator, the right operand, is inserted in the output stream. Notice that the operator points in the direction of where the data goes. The characters of the right operand normally print exactly as they appear between the double quotes. Notice, however, that the characters \n are not printed on the screen. The backslash (\) is called an escape character. It indicates that a &#8220;special&#8221; character is to be output. When a backslash is encountered in a string of characters, the next character is combined with the backslash to form an escape sequence. The escape sequence \n means newline. It causes the cursor (i.e., the current screen-position indicator) to move to the beginning of the next line on the screen.</p>
<pre style="text-align: justify;">system("pause");</pre>
<p style="text-align: justify;">This allows us to see the output of a function.  If we don’t apply system(“pause”); on the function it directly exits the console.</p>
<pre style="text-align: justify;">return 0; // indicate that program ended successfully</pre>
<p style="text-align: justify;">return 0 is one of several means we will use to exit a function. When the return statement is used at the end of main, as shown here, the value 0 indicates that the program has terminated successfully and the } indicated that the function is ended.</p>
<p class="buymebeer"><form action="https://www.paypal.com/cgi-bin/webscr" target="paypal" method="post"><input type="hidden" name="cmd" value="_xclick" /><input type="hidden" name="business" value="allajosephcagadas@gmail.com" /><input type="hidden" name="return" value="" /><input type="hidden" name="item_name" value="Can You Buy Me a Beer? for Hello World in C++" /><input type="hidden" name="currency_code" value="USD" /><input type="hidden" name="amount" value="" /><input type="image" src="http://www.icpep.org/wp-content/plugins/buy-me-beer/icon_beer.gif" align="left" alt="Buy Me a Beer" title="Buy Me a Beer" hspace="3" /></form><a href="https://www.paypal.com/cgi-bin/webscr?cmd=_xclick&amp;business=allajosephcagadas@gmail.com&amp;currency_code=USD&amp;amount=&amp;return=&amp;item_name=Can+You+Buy+Me+a+Beer?+for+Hello+World+in+C++" target="paypal">Did find the post very useful? Maybe you want to buy me a glass of beer!</a></p>]]></content:encoded>
			<wfw:commentRss>http://www.icpep.org/hello-world-in-c-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Hello World in C++</title>
		<link>http://www.icpep.org/hello-world-in-c/</link>
		<comments>http://www.icpep.org/hello-world-in-c/#comments</comments>
		<pubDate>Fri, 05 Dec 2008 00:44:13 +0000</pubDate>
		<dc:creator>paparts</dc:creator>
				<category><![CDATA[C++]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Add new tag]]></category>

		<guid isPermaLink="false">http://icpep.org/?p=64</guid>
		<description><![CDATA[#include // I/O library using namespace std; int main() { cout &#60;&#60; &#8220;Hello, world!&#8221; &#60;&#60; endl; } The // symbol is used as a rest-of-line comment symbol. Also, the program text can be placed in any position on the page, with white space between tokens being ignored. White space are characters such as blanks, tabs, [...]]]></description>
			<content:encoded><![CDATA[<div><script type="text/javascript"><!--
google_ad_client = "pub-4547412119801593";
/* trojan remover */
google_ad_slot = "2402475287";
google_ad_width = 250;
google_ad_height = 250;
// --></script><br />
<script src="http://pagead2.googlesyndication.com/pagead/show_ads.js" type="text/javascript"></script></div>
<p style="text-align: center;"><a href="http://icpep.org/wp-content/uploads/cplusplus.jpg"><img class="aligncenter size-medium wp-image-65" title="cplusplus" src="http://icpep.org/wp-content/uploads/cplusplus-300x299.jpg" alt="" width="300" height="299" /></a></p>
<p style="text-align: justify; padding-left: 30px;">#include  // I/O library<br />
using namespace std;<br />
int main()<br />
{<br />
cout &lt;&lt; &#8220;Hello, world!&#8221; &lt;&lt; endl;<br />
}</p>
<p style="text-align: justify;">The // symbol is used as a rest-of-line comment symbol. Also, the program text can be placed in any position on the page, with white space between tokens being ignored. White space are characters such as blanks, tabs, and new lines. White space, comments, and indentation of text are all used to create a well-documented, readable program but do not affect program semantics.</p>
<p style="text-align: justify; padding-left: 30px;">#include &lt;iostream&gt; // I/O library</p>
<p style="text-align: justify;">The C++ program is compiled after the preprocessor executes #-designated directives. The preprocessor precedes the compiler translation of the resulting program into machine code. The #include directive found in the example program hello.cpp imports any needed files, usually library definitions. In this case, the I/O library for a typical C++ compiler system is found in the file iostream. The compiler knows where to find this and other system files.</p>
<p style="text-align: justify; padding-left: 30px;">Using namespace std;</p>
<p style="text-align: justify;">On C++ systems, standard C++ I/O header files are wrapped in namespace std. The using declaration allows names to be used without std:: prepended to each name. The include files could have been coded without namespace and using, as follows:</p>
<p style="text-align: justify; padding-left: 30px;">#include &lt;iostream.h&gt; // I/O library</p>
<p style="text-align: justify;">Most systems provide older style library_name.h header files. These libraries do not require the using namespace std; statement.</p>
<p class="buymebeer"><form action="https://www.paypal.com/cgi-bin/webscr" target="paypal" method="post"><input type="hidden" name="cmd" value="_xclick" /><input type="hidden" name="business" value="allajosephcagadas@gmail.com" /><input type="hidden" name="return" value="" /><input type="hidden" name="item_name" value="Can You Buy Me a Beer? for Hello World in C++" /><input type="hidden" name="currency_code" value="USD" /><input type="hidden" name="amount" value="" /><input type="image" src="http://www.icpep.org/wp-content/plugins/buy-me-beer/icon_beer.gif" align="left" alt="Buy Me a Beer" title="Buy Me a Beer" hspace="3" /></form><a href="https://www.paypal.com/cgi-bin/webscr?cmd=_xclick&amp;business=allajosephcagadas@gmail.com&amp;currency_code=USD&amp;amount=&amp;return=&amp;item_name=Can+You+Buy+Me+a+Beer?+for+Hello+World+in+C++" target="paypal">Did find the post very useful? Maybe you want to buy me a glass of beer!</a></p>]]></content:encoded>
			<wfw:commentRss>http://www.icpep.org/hello-world-in-c/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>C++ Reading From a Text File</title>
		<link>http://www.icpep.org/c-reading-from-a-text-file/</link>
		<comments>http://www.icpep.org/c-reading-from-a-text-file/#comments</comments>
		<pubDate>Fri, 28 Nov 2008 12:52:10 +0000</pubDate>
		<dc:creator>paparts</dc:creator>
				<category><![CDATA[C++]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://icpep.org/?p=34</guid>
		<description><![CDATA[#include &#60;iostream&#62; #include &#60;fstream&#62; #include &#60;string&#62; using namespace std; int main() { string line; int count = 0; ifstream FileName (&#8220;try.txt&#8221;); if (FileName.is_open() &#38;&#38; !FileName.eof()){ while (getline(FileName,line)){ count++; } } else cout &#60;&#60; &#8220;Error opening file!&#8221; &#60;&#60; endl; cout &#60;&#60; &#8220;The number of lines in the file is &#8221; &#60;&#60; count &#60;&#60; endl; system(&#8220;pause&#8221;); } [...]]]></description>
			<content:encoded><![CDATA[<p style="text-align: justify;"><script type="text/javascript"><!--
google_ad_client = "pub-4547412119801593";
/* nvidea */
google_ad_slot = "2978597988";
google_ad_width = 250;
google_ad_height = 250;
// --></script><br />
<script src="http://pagead2.googlesyndication.com/pagead/show_ads.js" type="text/javascript"></script></p>
<p>#include &lt;iostream&gt;<br />
 #include &lt;fstream&gt;<br />
 #include &lt;string&gt;</p>
<p>using namespace std;</p>
<p>int main() {<br />
 string line;<br />
 int count = 0;<br />
 ifstream FileName (&#8220;try.txt&#8221;);<br />
 if (FileName.is_open() &amp;&amp; !FileName.eof()){<br />
 while (getline(FileName,line)){<br />
 count++;<br />
 }<br />
 }<br />
 else cout &lt;&lt; &#8220;Error opening file!&#8221; &lt;&lt; endl;</p>
<p>cout &lt;&lt; &#8220;The number of lines in the file is &#8221; &lt;&lt; count &lt;&lt; endl;</p>
<p>system(&#8220;pause&#8221;);</p>
<p>}<br />
 <script type="text/javascript"><!--
google_ad_client = "pub-4547412119801593";
/* 468x60, created 11/28/08 */
google_ad_slot = "5516812424";
google_ad_width = 468;
google_ad_height = 60;
// --></script><br />
<script src="http://pagead2.googlesyndication.com/pagead/show_ads.js" type="text/javascript"></script><br />
This program counts the number of lines in a text file. I used the getline function to count it. The getline function is used to create a string containing all of the characters from the input stream until the end of file is found or the delimiter.</p>
<p style="text-align: justify;">Its syntax is getline(char *s, streamsize n) or getline(char *s, streamsize n, char delimiter).<span id="more-34"></span></p>
<p style="text-align: justify;">The difference between them is that tche first one includes blank lines in counting while the second one contains a delimiter which can be any character depending on what you want to base your count on (e.g. newline). By replacing the getline function above with this getline(FileName, string, &#8216;\n&#8217;), it will count lines in the text with text and not include the blank lines.</p>
<p class="buymebeer"><form action="https://www.paypal.com/cgi-bin/webscr" target="paypal" method="post"><input type="hidden" name="cmd" value="_xclick" /><input type="hidden" name="business" value="allajosephcagadas@gmail.com" /><input type="hidden" name="return" value="" /><input type="hidden" name="item_name" value="Can You Buy Me a Beer? for C++ Reading From a Text File" /><input type="hidden" name="currency_code" value="USD" /><input type="hidden" name="amount" value="" /><input type="image" src="http://www.icpep.org/wp-content/plugins/buy-me-beer/icon_beer.gif" align="left" alt="Buy Me a Beer" title="Buy Me a Beer" hspace="3" /></form><a href="https://www.paypal.com/cgi-bin/webscr?cmd=_xclick&amp;business=allajosephcagadas@gmail.com&amp;currency_code=USD&amp;amount=&amp;return=&amp;item_name=Can+You+Buy+Me+a+Beer?+for+C+++Reading+From+a+Text+File" target="paypal">Did find the post very useful? Maybe you want to buy me a glass of beer!</a></p>]]></content:encoded>
			<wfw:commentRss>http://www.icpep.org/c-reading-from-a-text-file/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
