C++ For Dummies
eBook - ePub

C++ For Dummies

Stephen R. Davis

Share book
  1. English
  2. ePUB (mobile friendly)
  3. Available on iOS & Android
eBook - ePub

C++ For Dummies

Stephen R. Davis

Book details
Book preview
Table of contents
Citations

About This Book

The best-selling C++ For Dummies book makes C++ easier!

C++ For Dummies, 7 th Edition is the best-selling C++ guide on the market, fully revised for the 2014 update. With over 60% new content, this updated guide reflects the new standards, and includes a new Big Data focus that highlights the use of C++ among popular Big Data software solutions. The book provides step-by-step instruction from the ground up, helping beginners become programmers and allowing intermediate programmers to sharpen their skills. The companion website provides all code mentioned in the text, an updated GNU_C++, the new C++ compiler, and other applications. By the end of the first chapter, you will have programmed your first C++ application!

As one of the most commonly used programming languages, C++ is a must-have skill for programmers who wish to remain versatile and marketable. C++ For Dummies, 7 th Edition provides clear, concise, expert instruction, which is organized for easy navigation and designed for hands-on learning. Whether you're new to programming, familiar with other languages, or just getting up to speed on the new libraries, features, and generics, this guide provides the information you need.

  • Provides you with an introduction to C++ programming
  • Helps you become a functional programmer
  • Features information on classes, inheritance, and optional features
  • Teaches you 10 ways to avoid adding bugs

The book incorporates the newest C++ features into the fundamental instruction, allowing beginners to learn the update as they learn the language. Staying current on the latest developments is a crucial part of being a programmer, and C++ For Dummies, 7 th Edition gets you started off on the right foot.

Frequently asked questions

How do I cancel my subscription?
Simply head over to the account section in settings and click on “Cancel Subscription” - it’s as simple as that. After you cancel, your membership will stay active for the remainder of the time you’ve paid for. Learn more here.
Can/how do I download books?
At the moment all of our mobile-responsive ePub books are available to download via the app. Most of our PDFs are also available to download and we're working on making the final remaining ones downloadable now. Learn more here.
What is the difference between the pricing plans?
Both plans give you full access to the library and all of Perlego’s features. The only differences are the price and subscription period: With the annual plan you’ll save around 30% compared to 12 months on the monthly plan.
What is Perlego?
We are an online textbook subscription service, where you can get access to an entire online library for less than the price of a single book per month. With over 1 million books across 1000+ topics, we’ve got you covered! Learn more here.
Do you support text-to-speech?
Look out for the read-aloud symbol on your next book to see if you can listen to it. The read-aloud tool reads text aloud for you, highlighting the text as it is being read. You can pause it, speed it up and slow it down. Learn more here.
Is C++ For Dummies an online PDF/ePUB?
Yes, you can access C++ For Dummies by Stephen R. Davis in PDF and/or ePUB format, as well as other popular books in Informatique & Programmation en C. We have over one million books available in our catalogue for you to explore.

Information

Publisher
For Dummies
Year
2014
ISBN
9781118823835
Part I

Getting Started with C++ Programming

9781118823774-pp0101.tif
webextras.eps
Visit www.dummies.com for great Dummies content online.
In this part…
  • Explaining the building blocks
  • Declaring variables
  • Defining mathematical operators
  • Using logical operators
  • Visit www.dummies.com for great Dummies content online.
Chapter 1

Writing Your First C++ Program

In This Chapter
arrow
Finding out about C++
arrow
Installing Code::Blocks on Windows, Ubuntu Linux, or Macintosh OS X
arrow
Creating your first C++ program
arrow
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 it’s told — nothing more and nothing less.
Perhaps unfortunately for us, computers don’t understand any reasonable human language — they don’t speak English either. Okay, I know what you’re going to say: “I’ve seen computers that could understand English.” What you really saw was a computer executing a program that could meaningfully understand English.
Computers understand a language variously known as computer language or machine language. It’s possible but extremely difficult for humans to speak machine language. Therefore, computers and humans have agreed to sort of meet in the middle, using intermediate languages such as C++. Humans can speak C++ (sort of), and C++ can be converted into machine language for the computer to understand.

Grasping C++ Concepts

A C++ program is a text file containing a sequence of C++ commands put together according to the laws of C++ grammar. This text file is known as the source file (probably because it’s the source of all frustration). A C++ source file normally carries the extension .CPP just as an Adobe Acrobat file ends in .PDF or an MS-DOS (remember that?) batch file ends in .BAT.
The point of programming in C++ is to write a sequence of commands that can be converted into a machine-language program that actually does what we want done. This conversion is called compiling and is the job of the compiler. The machine code that you wrote must be combined with some setup and teardown instructions and some standard library routines in a process known as linking. Together, compiling and linking are known as building. The resulting machine-executable files carry the extension .EXE in Windows. They don't carry any particular extension in Linux or Macintosh.
That sounds easy enough — so what’s the big deal? Keep going.
To write a program, you need two specialized computer programs. One (an editor) is what you use to write your code as you build your .CPP source file. The other (a compiler) converts your source file into a machine-executable file that carries out your real-world commands (open spreadsheet, make rude noises, deflect incoming asteroids, whatever).
Nowadays, tool developers generally combine compiler and editor into a single package — a development environment. After you finish entering the commands that make up your program, you need only click a button to build the executable file.
Fortunately, there are public-domain C++ environments. I use one of them in this book — the Code::Blocks environment. This editor will work with a lot of different compilers, but the version of Code::Blocks combined with the GNU gcc compiler used to write this book is available for download for Windows, Macintosh, and various versions of Linux, as described in the installation section of this chapter.
Although Code::Blocks is public domain, you’re encouraged to pay some small fee to support its further development. You don’t have to pay to use Code::Blocks, but you can contribute to the cause if you like. See the Code::Blocks website for details.
I have tested the programs in this book with Code::Blocks 13.12 which comes bundled with gcc version 4.7.1. This version of gcc implements most of the C++ 2011 standard.
c++11_fmt.eps
You can use different versions of gcc or even different compilers if you prefer, but they may not implement the complete '11 standard. For that reason, 2011 extensions are marked with the '11 icon seen here.
c++14_fmt.eps
The gcc compiler does not implement any of the extensions added in the C++ 2014 standard as of this writing, but I have included them, where applicable, because some day it will.
Okay, I admit it: This book is somewhat Windows-centric. I have tested all of the programs in the book on Windows 2000/XP/Vista/7/8, Ubuntu Linux, and Macintosh OS X. I flag any differences between operating systems in the text. In addition, I include installation instructions for each of the above three operating systems in this chapter. Versions of Code::Blocks and gcc are available for other flavors of Linux and other versions of the Macintosh OS. The programs should work with these, as well.
warning.eps
The Code::Blocks/gcc package generates 32-bit programs, but it does not easily support creating “windowed” programs. The programs in this book run from a command line prompt and write out to the command line. As boring as that may sound, I strongly recommend that you work through the examples in this book fir...

Table of contents