C++ For Dummies, 7th Edition
Published by: John Wiley & Sons, Inc., 111 River Street, Hoboken, NJ 07030-5774, www.wiley.com
Copyright 2014 by John Wiley & Sons, Inc., Hoboken, New Jersey
Media and software compilation copyright 2014 by John Wiley & Sons, Inc. All rights reserved.
Published simultaneously in Canada
No part of this publication may be reproduced, stored in a retrieval system or transmitted in any form or by any means, electronic, mechanical, photocopying, recording, scanning or otherwise, except as permitted under Sections 107 or 108 of the 1976 United States Copyright Act, without the prior written permission of the Publisher. Requests to the Publisher for permission should be addressed to the Permissions Department, John Wiley & Sons, Inc., 111 River Street, Hoboken, NJ 07030, (201) 748-6011, fax (201) 748-6008, or online at http://www.wiley.com/go/permissions .
Trademarks: Wiley, For Dummies, the Dummies Man logo, Dummies.com, Making Everything Easier, and related trade dress are trademarks or registered trademarks of John Wiley & Sons, Inc. and may not be used without written permission. All other trademarks are the property of their respective owners. John Wiley & Sons, Inc. is not associated with any product or vendor mentioned in this book.
LIMIT OF LIABILITY/DISCLAIMER OF WARRANTY : THE PUBLISHER AND THE AUTHOR MAKE NO REPRESENTATIONS OR WARRANTIES WITH RESPECT TO THE ACCURACY OR COMPLETENESS OF THE CONTENTS OF THIS WORK AND SPECIFICALLY DISCLAIM ALL WARRANTIES, INCLUDING WITHOUT LIMITATION WARRANTIES OF FITNESS FOR A PARTICULAR PURPOSE. NO WARRANTY MAY BE CREATED OR EXTENDED BY SALES OR PROMOTIONAL MATERIALS. THE ADVICE AND STRATEGIES CONTAINED HEREIN MAY NOT BE SUITABLE FOR EVERY SITUATION. THIS WORK IS SOLD WITH THE UNDERSTANDING THAT THE PUBLISHER IS NOT ENGAGED IN RENDERING LEGAL, ACCOUNTING, OR OTHER PROFESSIONAL SERVICES. IF PROFESSIONAL ASSISTANCE IS REQUIRED, THE SERVICES OF A COMPETENT PROFESSIONAL PERSON SHOULD BE SOUGHT. NEITHER THE PUBLISHER NOR THE AUTHOR SHALL BE LIABLE FOR DAMAGES ARISING HEREFROM. THE FACT THAT AN ORGANIZATION OR WEBSITE IS REFERRED TO IN THIS WORK AS A CITATION AND/OR A POTENTIAL SOURCE OF FURTHER INFORMATION DOES NOT MEAN THAT THE AUTHOR OR THE PUBLISHER ENDORSES THE INFORMATION THE ORGANIZATION OR WEBSITE MAY PROVIDE OR RECOMMENDATIONS IT MAY MAKE. FURTHER, READERS SHOULD BE AWARE THAT INTERNET WEBSITES LISTED IN THIS WORK MAY HAVE CHANGED OR DISAPPEARED BETWEEN WHEN THIS WORK WAS WRITTEN AND WHEN IT IS READ. FULFILLMENT OF EACH COUPON OFFER IS THE SOLE RESPONSIBILITY OF THE OFFEROR.
For general information on our other products and services, please contact our Customer Care Department within the U.S. at 877-762-2974, outside the U.S. at 317-572-3993, or fax 317-572-4002. For technical support, please visit www.wiley.com/techsupport .
Wiley publishes in a variety of print and electronic formats and by print-on-demand. Some material included with standard print versions of this book may not be included in e-books or in print-on-demand. If this book refers to media such as a CD or DVD that is not included in the version you purchased, you may download this material at http://booksupport.wiley.com . For more information about Wiley products, visit www.wiley.com .
Library of Congress Control Number: 2013958400
ISBN 978-1-118-82377-4 (pbk); ISBN 978-1-118-82382-8 (ebk); ISBN 978-1-118-82383-5 (ebk)
Manufactured in the United States of America
10 9 8 7 6 5 4 3 2 1
About the Author
Stephen R. Davis, CISSP (who goes by the name Randy) lives with his wife and two dogs in Corpus Christi, Texas. Randy has three kids and two grand-kids with more on the way (grandkids, not kids). Randy develops browser-based applications for Agency Consulting Group.
Dedication
To Janet, the love of my life.
Authors Acknowledgments
I find it very strange that only a single name appears on the cover of any book, but especially a book like this. In reality, many people contribute to the creation of a For Dummies book. From the beginning, acquisitions editor Constance Santisteban, project editor Pat O'Brien, and my agent, Claudette Moore, were involved in guiding and molding the book's content. During the development of the seven editions of this book, I found myself hip-deep in edits, corrections, and suggestions from a group of project editors, copyeditors, and technical reviewers this book would have been a poorer work but for their involvement. And nothing would have made it into print without the aid of Suzanne Thomas, who coordinated the first and second editions of the book, Susan Pink, who worked on the third and sixth editions, Katie Feltman who worked on the sixth edition, and Danny Kalev, who did the technical review of the sixth and seventh editions. Nevertheless, one name does appear on the cover and that name must take responsibility for any inaccuracies in the text.
Finally, a summary of the animal activity around my house. For those of you who have not read any of my other books, I should warn you that this has become a regular feature of my For Dummies books.
I moved to the big city in 2005, which meant giving away our dogs Chester and Sadie. I tried to keep our two Great Danes, Monty and Bonnie, but they were just too much for the backyard. We were forced to give them away as well. I married my high school sweetheart in 2011 and moved from Dallas back to my home town of Corpus Christi which meant adopting a new pair of dogs (more like, they adopted me). Jack is a stubborn, black dog of an unidentifiable breed. Scruffy is said to be a wire haired dachshund but you couldn't tell by his appearance as he stays shaved most of the time.
If you are having problems getting started, I maintain a FAQ of common problems at www.stephendavis.com . You can e-mail me questions from there if you don't see your problem. I can't write your program (you don't know how often I get asked to do people's homework assignments), but I try to answer most questions.
Publishers Acknowledgments
Acquisitions Editor: Connie Santisteban
Project Editor: Pat OBrien
Copy Editor: Laura K. Miller
Technical Editor: Danny Kalev
Editorial Assistant: Anne Sullivan
Sr. Editorial Assistant: Cherie Case
Project Coordinator: Melissa Cossell
Cover Image: iStockphoto.com/gavni
Chapter 1
Writing Your First C++ Program
In This Chapter
Finding out about C++
Installing Code::Blocks on Windows, Ubuntu Linux, or Macintosh OS X
Creating your first C++ program
Executing your program
Okay, so here we are: No one here but just you and me. Nothing left to do but get started. Might as well lay out a few fundamental concepts.
A computer is an amazingly fast but incredibly stupid machine. A computer can do anything you tell it (within reason), but it does exactly what its told nothing more and nothing less.
Perhaps unfortunately for us, computers dont understand any reasonable human language they dont speak English either. Okay, I know what youre going to say: Ive seen computers that could understand English. What you really saw was a computer executing a program that could meaningfully understand English.
Next page