 




<?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>IT Bookworm Blog &#187; Programming</title>
	<atom:link href="http://itknowledgeexchange.techtarget.com/bookworm/tag/programming/feed/" rel="self" type="application/rss+xml" />
	<link>http://itknowledgeexchange.techtarget.com/bookworm</link>
	<description>Free sample chapters from IT books</description>
	<lastBuildDate>Tue, 14 May 2013 18:48:42 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	
		<item>
		<title>Book excerpt: C++ Primer, 5th Edition</title>
		<link>http://itknowledgeexchange.techtarget.com/bookworm/book-excerpt-c-primer-5th-edition/</link>
		<comments>http://itknowledgeexchange.techtarget.com/bookworm/book-excerpt-c-primer-5th-edition/#comments</comments>
		<pubDate>Thu, 04 Oct 2012 16:40:01 +0000</pubDate>
		<dc:creator>Ben Rubenstein</dc:creator>
				<category><![CDATA[Addison-Wesley]]></category>
		<category><![CDATA[Book excerpt]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[Developers]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://itknowledgeexchange.techtarget.com/bookworm/?p=685</guid>
		<description><![CDATA[The following is an excerpt from C++ Primer, Fifth Edition, by Stanley B. Lippman, Josee Lajoie and Barbara E. Moo, available from Addison-Wesley Professional.  For more information, read Jaideep Khanduja&#8217;s review of the full book.  1.2 A First Look at Input/Output The C++ language does not define any statements to do input or output (IO). Instead, C++ includes [...]]]></description>
				<content:encoded><![CDATA[<p>The following is an excerpt from C++ Primer, Fifth Editio<em>n, by Stanley B. Lippman, Josee Lajoie and Barbara E. Moo, available from <a title="C++ Primer from Addison Wesley Professional" href="http://www.informit.com/store/product.aspx?isbn=0321714113" target="_blank">Addison-Wesley Professional</a>. </em></p>
<p><em>For more information, read Jaideep Khanduja&#8217;s <a title="Review of C++ Primer" href="http://itknowledgeexchange.techtarget.com/quality-assurance/book-review-c11-primer-a-must-for-all-c-programmers-and-aspirants/">review of the full book</a>. </em></p>
<p><strong>1.2 A First Look at Input/Output</strong></p>
<p>The C++ language does not define any statements to do input or output (IO). Instead, C++ includes an extensive <strong>standar</strong>d <strong>librar</strong>y that provides IO (and many other facilities). For many purposes, including the examples in this book, one needs to know only a few basic concepts and operations from the IO library.</p>
<p>Most of the examples in this book use the <strong>iostrea</strong>m library. Fundamental to the iostream library are two types named <strong>istrea</strong>m and <strong>ostream</strong>,which represent input and output streams, respectively. A stream is a sequence of characters read from or written to an IO device. The term <em>stream </em>is intended to suggest that the characters are generated, or consumed, sequentially over time.</p>
<p><strong>Standard Input and Output Objects </strong></p>
<p>The library defines four IO objects. To handle input, we use an object of type istream named <strong>ci</strong>n (pronounced <em>see-in</em>). This object is also referred to as the <strong>standar</strong>d <strong>input</strong>. For output, we use an ostream object named <strong>cou</strong>t (pronounced <em>see-out</em>). This object is also known as the <strong>standar</strong>d <strong>output</strong>. The library also defines two other ostream objects, named <strong>cer</strong>r and <strong>clo</strong>g (pronounced <em>see-err </em>and <em>see-log</em>, respectively). We typically use cerr, referred to as the <strong>standar</strong>d <strong>error</strong>,for warning and error messages and clog for general information about the execution of the program.</p>
<p>Ordinarily, the system associates each of these objects with the window in which the program is executed. So, when we read from cin, data are read from the window in which the program is executing, and when we write to cout, cerr, or clog, the output is written to the same window.</p>
<p><strong>A Program That Uses the IO Library</strong></p>
<p>In our bookstore problem, we’ll have several records that we’ll want to combine into a single total. As a simpler, related problem, let’s look first at how we might add two numbers. Using the IO library, we can extend our main program to prompt the user to give us two numbers and then print their sum:</p>
<p>#include &lt;iostream&gt;</p>
<p>int main()</p>
<p>{</p>
<p>std::cout &lt;&lt; &#8220;Enter two numbers:&#8221; &lt;&lt; std::endl;</p>
<p>int v1= 0, v2 = 0;</p>
<p>std::cin &gt;&gt; v1 &gt;&gt; v2;</p>
<p>std::cout &lt;&lt; &#8220;The sum of &#8221; &lt;&lt; v1 &lt;&lt; &#8221; and &#8221; &lt;&lt; v2</p>
<p align="center">&lt;&lt; &#8221; is &#8221; &lt;&lt; v1 + v2 &lt;&lt; std::endl;</p>
<p>return 0;</p>
<p>}</p>
<p>This program starts by printing</p>
<p><strong>Enter two numbers:</strong></p>
<p>on the user’s screen and then waits for input from the user. If the user enters</p>
<p><strong>37</strong></p>
<p>followed by a newline, then the program produces the following output:</p>
<p><strong>The sum of 3 and 7 is 10</strong></p>
<p>The first line of our program</p>
<p>#include &lt;iostream&gt;</p>
<p>tells the compiler that we want to use the iostream library. The name inside angle brackets (iostream in this case) refers to a <strong>header</strong>. Every program that uses a library facility must include its associated header. The #include directive <strong>7 Sectio </strong>n <strong>1. </strong>2 A <strong>Firs </strong>t <strong>Loo </strong>k <strong>a </strong>t <strong>Input/Outpu </strong>t</p>
<p>must be written on a single line—the name of the header and the #include must appear on the same line. In general, #include directives must appear outside any function. Typically, we put all the #include directives for a program at the beginning of the source file.</p>
<p><strong>Writing to a Stream </strong></p>
<p>The first statement in the body of main executes an <strong>expression</strong>.In C++ an expression yields a result and is composed of one or more operands and (usually) an operator. The expressions in this statement use the output operator (the « <strong>operator</strong>) to print a message on the standard output:</p>
<p>std::cout &lt;&lt; &#8220;Enter two numbers:&#8221; &lt;&lt; std::endl;</p>
<p>The &lt;&lt; operator takes two operands: The left-hand operand must be an ostream object; the right-hand operand is a value to print. The operator writes the given value on the given ostream. The result of the output operator is its left-hand operand. That is, the result is the ostream on which we wrote the given value.</p>
<p>Our output statement uses the &lt;&lt; operator twice. Because the operator returns its left-hand operand, the result of the first operator becomes the left-hand operand of the second. As a result, we can chain together output requests. Thus, our expression is equivalent to</p>
<p>(std::cout &lt;&lt; &#8220;Enter two numbers:&#8221;) &lt;&lt; std::endl;</p>
<p>Each operator in the chain has the same object as its left-hand operand, in this case std::cout. Alternatively, we can generate the same output using two statements:</p>
<p>std::cout &lt;&lt; &#8220;Enter two numbers:&#8221;;std::cout &lt;&lt; std::endl;</p>
<p>The first output operator prints a message to the user. That message is a <strong>strin</strong>g <strong>literal</strong>, which is a sequence of characters enclosed in double quotation marks. The text between the quotation marks is printed to the standard output.</p>
<p>The second operator prints endl, which is a special value called a <strong>manipulator</strong>.Writing endl has the effect of ending the current line and flushing the <strong><em>buffe</em></strong>r associated with that device. Flushing the buffer ensures that all the output the program has generated so far is actually written to the output stream, rather than sitting in memory waiting to be written. Programmers often add print statements during debugging. Such statements should <em>always </em>flush the stream. Otherwise, if the program crashes, output may be left in the buffer, leading to incorrect inferences about where the program crashed.</p>
<p><strong>Using Names from the Standard Library</strong></p>
<p>Careful readers will note that this program uses std::cout and std::endl rather than just cout and endl.The prefix std:: indicates that the names cout and endl are defined inside the <strong>namespac</strong>e named <strong>std</strong>. Namespaces allow us to</p>
<p>avoid inadvertent collisions between the names we define and uses of those same names inside a library. All the names defined by the standard library are in the std namespace.</p>
<p>One side effect of the library’s use of a namespace is that when we use a name from the library, we must say explicitly that we want to use the name from the std namespace. Writing std::cout uses the scope operator (the <strong>:</strong>: <strong>operator</strong>)tosay that we want to use the name cout that is defined in the namespace std.§ 3.1</p>
<p>(p. 82) will show a simpler way to access names from the library.</p>
<p><strong>Reading from a Stream </strong></p>
<p>Having asked the user for input, we next want to read that input. We start by defining two <strong><em>variable</em></strong>s named v1 and v2 to hold the input:</p>
<p>intv1 = 0, v2 =0;</p>
<p>We define these variables as type int, which is a built-in type representing integers. We also <strong><em>initializ</em></strong>e them to 0. When we initialize a variable, we give it the indicated value at the same time as the variable is created.</p>
<p>The next statement</p>
<p>std::cin &gt;&gt; v1 &gt;&gt; v2;</p>
<p>reads the input. The input operator (the » <strong>operator</strong>) behaves analogously to the output operator. It takes an istream as its left-hand operand and an object as its right-hand operand. It reads data from the given istream and stores what was read in the given object. Like the output operator, the input operator returns its left-hand operand as its result. Hence, this expression is equivalent to</p>
<p>(std::cin &gt;&gt; v1) &gt;&gt; v2;</p>
<p>Because the operator returns its left-hand operand, we can combine a sequence of input requests into a single statement. Our input operation reads two values from std::cin, storing the first in v1 and the second in v2.In other words, our input operation executes as</p>
<p>std::cin &gt;&gt; v1;std::cin &gt;&gt; v2;</p>
<p><strong>Completing the Program</strong></p>
<p>What remains is to print our result:</p>
<p>std::cout &lt;&lt; &#8220;The sum of &#8221; &lt;&lt; v1 &lt;&lt; &#8221; and &#8221; &lt;&lt; v2&lt;&lt; &#8221; is &#8221; &lt;&lt; v1 + v2 &lt;&lt; std::endl;</p>
<p>This statement, although longer than the one that prompted the user for input, is conceptually similar. It prints each of its operands on the standard output. What is interesting in this example is that the operands are not all the same kinds of values. Some operands are string literals, such as &#8220;The sum of &#8220;.Others are int values, such as v1, v2, and the result of evaluating the arithmetic expression v1+v2. The library defines versions of the input and output operators that handle operands of each of these differing types.</p>
<!-- wpms-network-global-inserts -->]]></content:encoded>
			<wfw:commentRss>http://itknowledgeexchange.techtarget.com/bookworm/book-excerpt-c-primer-5th-edition/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>KFaganJr&#8217;s Review of &#8220;Drupal&#8217;s Building Blocks&#8221;</title>
		<link>http://itknowledgeexchange.techtarget.com/bookworm/kfaganjrs-review-of-drupals-building-blocks/</link>
		<comments>http://itknowledgeexchange.techtarget.com/bookworm/kfaganjrs-review-of-drupals-building-blocks/#comments</comments>
		<pubDate>Tue, 12 Apr 2011 15:36:03 +0000</pubDate>
		<dc:creator>Guest Author</dc:creator>
				<category><![CDATA[Developers]]></category>
		<category><![CDATA[Drupal]]></category>
		<category><![CDATA[Drupal's Building Blocks]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://itknowledgeexchange.techtarget.com/bookworm/kfaganjrs-review-of-drupals-building-blocks/</guid>
		<description><![CDATA[Member KFaganJr agreed to review Drupal&#8217;s Building Blocks. If you&#8217;d like to review a book for the Bookworm Blog, send me an email at Melanie at ITKnowledgeExchange.com to express your interest. Disclosure: The publisher of the book provided a free copy for this review. Drupal&#8217;s Building Blocks is one of the few books that I&#8217;ve [...]]]></description>
				<content:encoded><![CDATA[<p><a href="http://itknowledgeexchange.techtarget.com/itanswers/win-drupals-building-blocks/"><img class="alignright" style="margin: 10px" src="http://drupal-building-blocks.com/sites/default/files/cover-small.jpg" alt="" width="174" height="225" /></a><em>Member <a href="http://itknowledgeexchange.techtarget.com/profile/kfaganjr/" target="_blank">KFaganJr</a> agreed to review</em> <a href="http://drupal-building-blocks.com/" target="_blank">Drupal&#8217;s Building Blocks</a>. <em>If you&#8217;d like to review a book for the Bookworm Blog, send me an email at Melanie at ITKnowledgeExchange.com to express your interest. Disclosure: The publisher of the book provided a free copy for this review.</em></p>
<p><em>Drupal&#8217;s Building Blocks </em>is one of the few books that I&#8217;ve come across that fit the middle ground Drupal users nicely. They are often geared toward beginners focused on using add-on modules or really advanced programmers/developers. What stood out the most to me was how the author explained what settings meant instead of just telling me what to choose. This really helped me to get a whole new grasp on views and got me started using panels. It&#8217;s almost embarrassing now to say. The book really covers the crucial building blocks of Drupal and provides information that takes you over common hurdles. It&#8217;s a must-have for developers experienced in making Drupal work for them, but aren&#8217;t far enough along to provide a working solution without experimenting.</p>
<p>Interested in getting your hands on this book? You&#8217;re in luck! This week&#8217;s <a href="http://itknowledgeexchange.techtarget.com/itanswers/win-drupals-building-blocks/" target="_blank">free IT book giveaway</a> is another copy of <em>Drupal&#8217;s Building Blocks. </em>So head over and <a href="http://itknowledgeexchange.techtarget.com/itanswers/win-drupals-building-blocks/" target="_blank">get started</a>!</p>
<!-- wpms-network-global-inserts -->]]></content:encoded>
			<wfw:commentRss>http://itknowledgeexchange.techtarget.com/bookworm/kfaganjrs-review-of-drupals-building-blocks/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
