Herb Schildts C++
Programming Cookbook
About the Author
Herbert Schildt is a leading authority on C++, C, Java, and C#, and is a master Windows programmer. His programming books have sold more than 3.5 million copies worldwide and have been translated into all major foreign languages. He is the author of numerous bestsellers on C++, including C++: The Complete Reference, C++: A Beginners Guide, C++ from the Ground Up, and STL Programming from the Ground Up. His other bestsellers include C#: The Complete Reference, Java: The Complete Reference, C: The Complete Reference, and Herb Schildts Java Programming Cookbook. Schildt holds both graduate and undergraduate degrees from the University of Illinois. He can be reached at his consulting office at (217) 586-4683. His website is www.HerbSchildt.com.
About the Technical Editor
Jim Keogh introduced PC programming nationally in his Popular Electronics Magazine column in 1982, four years after Apple Computer started in a garage.
He was a team member who built one of the first Windows applications by a Wall Street firm, featured by Bill Gates in 1986. Keogh has spent about two decades developing computer systems for Wall Street firms, such as Salomon, Inc. and Bear Stearns, Inc.
Keogh was on the faculty of Columbia University where he taught technology courses, including the Java Development lab. He developed and chaired the electronic commerce track at Columbia University. Keogh is presently on the faculty of New York University. He is the author of J2EE: The Complete Reference, J2ME: The Complete Reference, both published by McGraw-Hill, and more than 55 other titles, including five in the popular For Dummies series. His other books include Linux Programming for Dummies, Unix Programming for Dummies, Java Database Programming for Dummies, Essential Guide to Networking, Essential Guide to Computer Hardware, The C++ Programmers Notebook, and E-Mergers.
Herb Schildts C++
Programming Cookbook
Herb Schildt
New York Chicago San Francisco
Lisbon London Madrid Mexico City
Milan New Delhi San Juan
Seoul Singapore Sydney Toronto
Schildt, Herbert.
[C++ programming cookbook]
Herb Schildt's C++ programming cookbook / Herb Schildt.
p. cm.
1. C++ (Computer program language) I. Title. II. Title: C++
programming cookbook.
QA76.73.C153S325 2008
005.13'3-dc22
2008014989
Herb Schildts C++ Programming Cookbook
Copyright 2008 by The McGraw-Hill Companies. All rights reserved. Except as permitted under the United States Copyright Act of 1976, no part of this publication may be reproduced or distributed in any form or by any means, or stored in a database or retrieval system, without the prior written permission of the publisher.
ISBN: 978-0-07-164385-6
MHID: 0-07-164385-0
The material in this eBook also appears in the print version of this title: ISBN 978-0-07-148860-0, MHID 0-07-148860-X.
All trademarks are trademarks of their respective owners. Rather than put a trademark symbol after every occurrence of a trademarked name, we use names in an editorial fashion only, and to the benefit of the trademark owner, with no intention of infringement of the trademark. Where such designations appear in this book, they have been printed with initial caps.
McGraw-Hill eBooks are available at special quantity discounts to use as premiums and sales promotions, or for use in corporate training programs. To contact a representative please e-mail us at .
Sponsoring Editor
Wendy Rinaldi
Editorial Supervisor
Patty Mon
Project Manager
Vasundhara Sawhney, International Typesetting and Composition
Acquisitions Coordinator
Mandy Canales
Technical Editor
Jim Keogh
Copy Editor
Lisa McCoy
Proofreader
Andrea Fox
Indexer
Sheryl Schildt
Production Supervisor
Jean Bodeaux
Composition
International Typesetting and Composition
Illustration
International Typesetting and Composition
Art Director, Cover
Jeff Weeks
Cover Designer
12E Design
TERMS OF USE
This is a copyrighted work and The McGraw-Hill Companies, Inc. (McGraw-Hill) and its licensors reserve all rights in and to the work. Use of this work is subject to these terms. Except as permitted under the Copyright Act of 1976 and the right to store and retrieve one copy of the work, you may not decompile, disassemble, reverse engineer, reproduce, modify, create derivative works based upon, transmit, distribute, disseminate, sell, publish or sublicense the work or any part of it without McGraw-Hills prior consent. You may use the work for your own noncommercial and personal use; any other use of the work is strictly prohibited. Your right to use the work may be terminated if you fail to comply with these terms.
THE WORK IS PROVIDED AS IS. McGRAW-HILL AND ITS LICENSORS MAKE NO GUARANTEES OR WARRANTIES AS TO THE ACCURACY, ADEQUACY OR COMPLETENESS OF OR RESULTS TO BE OBTAINED FROM USING THE WORK, INCLUDING ANY INFORMATION THAT CAN BE ACCESSED THROUGH THE WORK VIA HYPERLINK OR OTHERWISE, AND EXPRESSLY DISCLAIM ANY WARRANTY, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. McGraw-Hill and its licensors do not warrant or guarantee that the functions contained in the work will meet your requirements or that its operation will be uninterrupted or error free. Neither McGraw-Hill nor its licensors shall be liable to you or anyone else for any inaccuracy, error or omission, regardless of cause, in the work or for any damages resulting therefrom. McGraw-Hill has no responsibility for the content of any information accessed through the work. Under no circumstances shall McGraw-Hill and/or its licensors be liable for any indirect, incidental, special, punitive, consequential or similar damages that result from the use of or inability to use the work, even if any of them has been advised of the possibility of such damages. This limitation of liability shall apply to any claim or cause whatsoever whether such claim or cause arises in contract, tort or otherwise.
Contents
Preface
O ver the years, friends and readers have asked me to write a programming cookbook, sharing some of the techniques and approaches that I use when I program. From the start, I liked the idea, but was unable to make time for it in my very busy writing schedule. As many readers know, I write extensively about several facets of programming, with a special focus on C++, Java, and C#. Because of the rapid revision cycles of those languages, I spend nearly all of my available time updating my books to cover the latest versions. Fortunately, early in 2007, a window of opportunity opened and I was finally able to devote time to the cookbook. The two most requested cookbooks were ones for Java and C++. I began with Java, with the result being my Java programming cookbook. As soon as I finished the Java book, I moved on to C++. The result is, of course, this book. I must admit that both projects were among my most enjoyable.
Based on the format of a traditional food cookbook, this book distills the essence of many general-purpose C++ techniques into a collection of step-by-step