<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:blogger='http://schemas.google.com/blogger/2008' xmlns:georss='http://www.georss.org/georss' xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-6233766959691512944</id><updated>2024-08-30T22:18:40.461+07:00</updated><category term="C++"/><category term="Programming"/><title type='text'>chiegv corner</title><subtitle type='html'>Your one stop information center</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://chiegv.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6233766959691512944/posts/default?redirect=false'/><link rel='alternate' type='text/html' href='http://chiegv.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>chiegv</name><uri>http://www.blogger.com/profile/16436760727526964604</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://1.bp.blogspot.com/_fDjkfDrXbos/Su8bpUba2JI/AAAAAAAAAAM/3CFKlS95px4/S220/21082009148.jpg'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>2</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-6233766959691512944.post-8359047525698180774</id><published>2009-11-03T21:24:00.002+07:00</published><updated>2009-11-04T02:19:13.656+07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="C++"/><category scheme="http://www.blogger.com/atom/ns#" term="Programming"/><title type='text'>Learn C++ (Console Application)   - Part 2 -</title><content type='html'>&lt;span style=&quot;font-weight:bold;&quot;&gt;Input and Output in C++&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;C language have some routines for I/O (Input/Output) which is declared with header stdio.h. This version is still usable at C++. But anyway, C++ introduce a new technique for I/O process, which is named iostreams or streams. Almost all function on stdio.h could be converted into streams. The pros about streams compare to I/O on C is their flexibility for formatting I/O and their ability to support overloaded operator concept.&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;font-weight:bold;&quot;&gt;What is Streams ?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Streams is abstraction to handle data flow from one source (producer) to another destination (consumer). Either source or destination could be act as buffer in memory, string, file, or monitor screen. C++ declare class for stream in some header files, i.e :&lt;br /&gt;[*] iostream.h (general I/O)&lt;br /&gt;[*] constrea.h (console I/O)&lt;br /&gt;[*] strstrea.h (string I/O)&lt;br /&gt;[*] fstream.h (file I/O)&lt;br /&gt;&lt;br /&gt;Stream for Output&lt;br /&gt;To do output process, operator &lt;&lt; is used, with general syntax &lt;span style=&quot;font-style:italic;&quot;&gt;stream_object &lt;&lt; data&lt;/span&gt;.&lt;br /&gt;&lt;br /&gt;stream_object is one of the object from stream class.&lt;br /&gt;data is your output.&lt;br /&gt;&lt;br /&gt;#include&lt;br /&gt;&lt;br /&gt;void main()&lt;br /&gt;{&lt;br /&gt;  cout &lt;&lt; &quot;Learn C++&quot;;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;Above statement will write string &quot;Learn C++&quot; to cout&#39;s stream. Cout is a stream for output to your monitor screen. You could also use &lt;&lt; in leveled, i.e :&lt;br /&gt;&lt;br /&gt;#include&lt;br /&gt;&lt;br /&gt;void main()&lt;br /&gt;{&lt;br /&gt;  cout &lt;&lt; &quot;Learn&quot; &lt;&lt; &quot; C++&quot; &lt;&lt; &#39;n&#39;;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;Identifier which had scalar data type could be written to output with stream. ex :&lt;br /&gt;&lt;br /&gt;#include&lt;br /&gt;&lt;br /&gt;void main()&lt;br /&gt;{&lt;br /&gt;  int x=10;&lt;br /&gt;  float y=20.0;&lt;br /&gt;  cout &lt;&lt; &quot;x = &quot; &lt;&lt; x &lt;&lt; &quot; y = &quot; &lt;&lt; y;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;output for above program : x = 10 y = 20&lt;br /&gt;&lt;br /&gt;output stream could also write identity address, ex :&lt;br /&gt;&lt;br /&gt;#include&lt;br /&gt;&lt;br /&gt;void main()&lt;br /&gt;{&lt;br /&gt;  int x;&lt;br /&gt;  cout &lt;&lt; &amp;x; //write variable x&#39;s address&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;output for above program : 0x8f98fff4&lt;br /&gt;&lt;br /&gt;Format Output with Function&lt;br /&gt;We can format stream output just like output with printf function. To do that, you need to change some bit flag on ios class. There are different kinds of bit flag on ios class, like :&lt;br /&gt;&lt;br /&gt;Flag Bit Statement&lt;br /&gt;skipws 0 : ignore white space while input process&lt;br /&gt;left 1 : left justify&lt;br /&gt;right 2 : right justify&lt;br /&gt;internal 3 : implied output with padding character after positive or base sign&lt;br /&gt;dec 4 : show output in decimal base&lt;br /&gt;oct 5 : show output in octal base&lt;br /&gt;hex 6 : show output in hexadecimal base&lt;br /&gt;showbase 7 : show output base&lt;br /&gt;showpoint 8 : show point (.) on real output&lt;br /&gt;uppercase 9 : capitalize hexadecimal output&lt;br /&gt;showpos 10 : show (+) if the output is more than zero&lt;br /&gt;scientific 11 : exponential mode for real output (format : XXXE()xxx)&lt;br /&gt;fixed 12 : decimal format for real output&lt;br /&gt;unitbuf 13 : empty all stream&lt;br /&gt;stdio 14 : prevent problem occurred if using stream and stdio together&lt;br /&gt;&lt;br /&gt;Flash about Flag&lt;br /&gt;Flag is bits, where every bit epitomize certain condition. Simplest example is flag 1 bit only epitomize condition true (&quot;1&quot;) or false (&quot;0&quot;).&lt;br /&gt;&lt;br /&gt;Another Format Output&lt;br /&gt;The most applied function for formatting, i.e :&lt;br /&gt;[*] int width (int) : change output width, ex :&lt;br /&gt;&lt;br /&gt;C :&lt;br /&gt;#include&lt;br /&gt;void main()&lt;br /&gt;{&lt;br /&gt;int x=10;&lt;br /&gt;printf(&quot;x = %4d&quot;, x);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;C++ :&lt;br /&gt;#include&lt;br /&gt;void main()&lt;br /&gt;{&lt;br /&gt;int x=10;&lt;br /&gt;cout.width(4);&lt;br /&gt;cout &lt;&lt; &quot;x = &quot; &lt;&lt; x;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;output for above programs :&lt;br /&gt;x = 10&lt;br /&gt;&lt;br /&gt;[*] char fill (char) : to change padding character. padding character is one of ASCII character which will be written if format output is bigger than stated width. ex :&lt;br /&gt;&lt;br /&gt;C :&lt;br /&gt;#include&lt;br /&gt;void main()&lt;br /&gt;{&lt;br /&gt;int x=10;&lt;br /&gt;printf(&quot;x = %04d&quot;, x);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;C++ :&lt;br /&gt;#include&lt;br /&gt;void main()&lt;br /&gt;{&lt;br /&gt;int x=10;&lt;br /&gt;cout.fill(&#39;0&#39;);&lt;br /&gt;cout.width(4);&lt;br /&gt;cout &lt;&lt; &quot;x = x &lt;&lt; x;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;output for above programs :&lt;br /&gt;x = 0010&lt;br /&gt;&lt;br /&gt;You can change 0 fill with another character, such as X, so the output would be XX10.&lt;br /&gt;&lt;br /&gt;[*] int precision (int) : adjust precision degree of real output (floating point). ex :&lt;br /&gt;&lt;br /&gt;C :&lt;br /&gt;#include&lt;br /&gt;void main()&lt;br /&gt;{&lt;br /&gt;float y=123.45;&lt;br /&gt;printf(&quot;y = %10.2f\n&quot;, y);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;versi C++ :&lt;br /&gt;#include&lt;br /&gt;void main()&lt;br /&gt;{&lt;br /&gt;float y=123.45;&lt;br /&gt;cout.width(10);&lt;br /&gt;cout.precision(5);&lt;br /&gt;cout &lt;&lt; &quot;y = &quot; &lt;&lt; y;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;output for above programs :&lt;br /&gt;y = 123.45&lt;br /&gt;&lt;br /&gt;to be continued..</content><link rel='replies' type='application/atom+xml' href='http://chiegv.blogspot.com/feeds/8359047525698180774/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://chiegv.blogspot.com/2009/11/learn-c-console-application-part-2.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6233766959691512944/posts/default/8359047525698180774'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6233766959691512944/posts/default/8359047525698180774'/><link rel='alternate' type='text/html' href='http://chiegv.blogspot.com/2009/11/learn-c-console-application-part-2.html' title='Learn C++ (Console Application)   - Part 2 -'/><author><name>chiegv</name><uri>http://www.blogger.com/profile/16436760727526964604</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://1.bp.blogspot.com/_fDjkfDrXbos/Su8bpUba2JI/AAAAAAAAAAM/3CFKlS95px4/S220/21082009148.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6233766959691512944.post-7220036584039717904</id><published>2009-11-02T23:23:00.001+07:00</published><updated>2009-11-04T02:19:47.749+07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="C++"/><category scheme="http://www.blogger.com/atom/ns#" term="Programming"/><title type='text'>Learn C++ (Console Application)   - Part 1 -</title><content type='html'>How to Start:&lt;br /&gt;&lt;br /&gt;1. open your application.&lt;br /&gt;2. select file, new, under Projects tab choose Win32 Console Application&lt;br /&gt;3. insert your project&#39;s name and where you want to save it in right pane&lt;br /&gt;4. choose &quot;An empty projet&quot; radio button.&lt;br /&gt;5. click finish (click OK for the next dialog box that pops out).&lt;br /&gt;&lt;br /&gt;now you will see your development environment.&lt;br /&gt;&lt;br /&gt;6. find Project on top menu bar, select Add to Project - New&lt;br /&gt;7. under Files tab, select C++ Source File&lt;br /&gt;8. type in file name and press OK&lt;br /&gt;9. and now you are ready to typing your c++ console application</content><link rel='replies' type='application/atom+xml' href='http://chiegv.blogspot.com/feeds/7220036584039717904/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://chiegv.blogspot.com/2009/11/learn-c-console-application-part-1.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6233766959691512944/posts/default/7220036584039717904'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6233766959691512944/posts/default/7220036584039717904'/><link rel='alternate' type='text/html' href='http://chiegv.blogspot.com/2009/11/learn-c-console-application-part-1.html' title='Learn C++ (Console Application)   - Part 1 -'/><author><name>chiegv</name><uri>http://www.blogger.com/profile/16436760727526964604</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://1.bp.blogspot.com/_fDjkfDrXbos/Su8bpUba2JI/AAAAAAAAAAM/3CFKlS95px4/S220/21082009148.jpg'/></author><thr:total>0</thr:total></entry></feed>