C++ Cookbook
Solutions and Examples for C++ Programmers
Publisher: O'Reilly Media
Final Release Date: November 2005
Pages: 594

Despite its highly adaptable and flexible nature, C++ is also one of the more complex programming languages to learn. Once mastered, however, it can help you organize and process information with amazing efficiency and quickness.

The C++ Cookbook will make your path to mastery much shorter. This practical, problem-solving guide is ideal if you're an engineer, programmer, or researcher writing an application for one of the legions of platforms on which C++ runs. The algorithms provided in C++ Cookbook will jump-start your development by giving you some basic building blocks that you don't have to develop on your own.

Less a tutorial than a problem-solver, the book addresses many of the most common problems you're likely encounter--whether you've been programming in C++ for years or you're relatively new to the language. Here are just some of the time-consuming tasks this book contains practical solutions for:

  • Reading the contents of a directory
  • Creating a singleton class
  • Date and time parsing/arithmetic
  • String and text manipulation
  • Working with files
  • Parsing XML
  • Using the standard containers

Typical of O'Reilly's "Cookbook" series, C++ Cookbook is written in a straightforward format, featuring recipes that contain problem statements and code solutions, and apply not to hypothetical situations, but those that you're likely to encounter. A detailed explanation then follows each recipe in order to show you how and why the solution works. This question-solution-discussion format is a proven teaching method, as any fan of the "Cookbook" series can attest to. This book will move quickly to the top of your list of essential C++ references.

Table of Contents
Product Details
About the Author
Recommended for You
Customer Reviews


by PowerReviews
oreillyC++ Cookbook

(based on 4 reviews)

Ratings Distribution

  • 5 Stars



  • 4 Stars



  • 3 Stars



  • 2 Stars



  • 1 Stars



Reviewed by 4 customers

Displaying reviews 1-4

Back to top

(1 of 1 customers found this review helpful)


So-so content

By Azhrei

from Tampa, FL

About Me Designer, Developer, Educator, Sys Admin

Verified Reviewer


  • Easy to understand
  • Well-organized


  • Not comprehensive enough
  • Too basic

Best Uses

  • Novice
  • Student

Comments about oreilly C++ Cookbook:

I bought this book to determine whether I could use it to assist in teaching an intermediate C++ course that I'm writing. I found the recipes to be too basic.

For example, recipe 7.11 is called "Printing a Range to a Stream", and it demonstrates how to use stream iterators (great) but when it comes to customizing how the output looks, the author switches to creating a global function that is called using a different API compared to std::copy() as was used in the recipe. I would have preferred to see a sample implementation of a custom stream iterator that has additional options for formatting and that would work using the std::copy() algorithm just described.

Another example is 8.9, "Creating a Singleton Class". While creating a singleton is extremely easy, it is virtually impossible to do it correctly in all situations. What order are singletons created in (in case one depends on another, such as a singleton that uses std::cout in its constructor)? What about destructors -- what order are they called in? And there's nothing about thread-safety and that's a critical consideration.

Recipes 10.4 and 10.5 deal with writing an object to a stream and reading it back in again. Writing to a stream is simple, but strings cannot be read back in the same way they are written (spaces in a string are treated as delimiters when reading). Yet recipe 10.5 completely misses -- the code won't work if spaces are added to the strings being printed! In my own work I have derived a new "dstring" class from "std::string" that adds delimiters on output, when necessary, so that the data can be properly read back in later.

This book is a "cookbook", meaning it should be short snippets of code that solve a particular problem, with a little discussion to describe the pitfalls (performance, memory use, etc). While the discussion does include "how the code works", it doesn't provide adequate coverage of the pitfalls. (For that, I recommend "Modern C++ Design" by Andrei Alexandrescu. It's not an easy read -- you'll need your thinking cap on! -- but it will open your eyes to things you've been doing wrong for years.)

(I'm also not thrilled with the Windows-centric comments and code. For example, using backslashes in pathnames. Forward slashes are portable across Windows and Unix and there is NO excuse for using backslashes in hard-coded pathnames. And in the callout of one recipe is a note that the author has to type Enter, Ctrl-Z, Enter to effect an end-of-file condition on Windows and "other platforms will be similar". Bad phrasing. Other platforms do use control keys, but that's where the similarity ends.)

I have indicated, "Yes, I would recommend this to a friend", but there would be caveats: my friend would need to be a beginner or someone who was going to work in C++ only sporadically, and I would advise that friend that some recipes are not as complete as they could be. Still, there are things that a beginner or student could learn from this text.

(3 of 4 customers found this review helpful)


C++ Cookbook, the best C++ guide ,

By Michal Jagiela

from Undisclosed

Comments about oreilly C++ Cookbook:

When I get a C++ Cookbook to my hand I think what I find in this book? I learn C++ from a much books, and everything it's very boring and hardly to learn. My first travel to C++ world with this book is very, very good and I love this book. C++ Cookbook is very friendly and easy to learn, full guide for all people who's interesting get a professional information about programming in this language.

Four authors in good, practice chapters summary all main and additional programming techniques for C++. All topics illustrated with useful examples from real world.

C++ Cookbook have very useful format, all chapters presented problem, detail describe solution and discuss about potential problem and possibilities to quick resolve all hardly point in C++ programming. I think this is the best method to learn for all people, from hobbyst who's interesting to discover features in C++ and easy learn to professional who's interesting find all required information for realize real-world problem at the C++ solutions.

Additional C++ Cookbooks is good pocket reference all features and functions C++ language. You can easily find short information about every features in general C++ language and additional standard libraries. Absolutly great and useful for all people!

With this book You can quickly learn C++ and going from novice to professional C++ developer.

With this book You can to the TechED events and become a C++ speaker , seriously!

(4 of 8 customers found this review helpful)


Fine Book, but Poorly Copy-Edited

By Todd C. S.

from Undisclosed

Comments about oreilly C++ Cookbook:

The C++ Cookbook is a fine title, but the copy editing is pretty atrocious. Probably the most egregious example is the entire section on "Matricies" [sic]. That spelling appears over and over again-- in the table of contents, as the section header, in the body text of that section, and in the index. O'reilly is known for the quality of its work, but this is an unfortunate counter-example.

(2 of 2 customers found this review helpful)


One of the best, most practical and useful C++ books ever.

By Clau3107

from Undisclosed

Comments about oreilly C++ Cookbook:

I've found this book unique; it tells you how to do many things and solve many problems in C++ easily. This book it's an absolute must-have book, even for experienced C++ developers.

Displaying reviews 1-4

Back to top

Buy 2 Get 1 Free Free Shipping Guarantee
Buying Options
Immediate Access - Go Digital what's this?
Ebook:  $39.99
Formats:  DAISY, ePub, Mobi, PDF
Print & Ebook:  $54.99
Print:  $49.99