Since I have AC++ to hand, i flicked to Section 3. The book should briefly mention a library facility called
sort, which exists in the
<algorithm> header
sort is one of those really useful functions, because it makes a traditionally fiddly programming task really easy. All you need to do is
CODE
sort( wordlist.begin(), wordlist.end() );
To count the unique entries should be easy now. You know that all duplicates have been lined up next to each other in the vector. You can examine every element in your vector in order, and compare it to its predecessor (Obviously, the first word is a special case, because it doesn't have a predecessor).
As for leaving the loop, AC++ makes the assumption that you know how to cause cin to turn 'bad'. On *nix and windows machines you can usually achieve this in console applications by pressing Ctrl+C. Otherwise, as VernonDozier said, your
while block will go on forever.
Re: Books - AC++ is undoubtedly a great beginners' book. whether its right for you depends how comfortable you feel with it so far - its a very to-the-point book, which doesn't waste paper with long explanations, and crams more useful information in per page than almost any other book I've seen. This makes it quite heavy-going if C++ is your first programming language, although it encourages learning-by-example, and learning by making mistakes for yourself (Unlike some books which spend pages overloading you with details on everything which can go wrong). if you've reached the end of Ch3 without too many problems, then you're doing well IMHO.
AC++ certainly isn't a "read once" book. I've personally been through it two or three times in some detail (And used it as a reference on many other occasions). So don't worry if you feel that you've missed out on bits and pieces. Some experienced C++ programmers I know also claim to have learned more than a few new tricks just from reading the examples.
This post has been edited by Bench: 26 Jan, 2008 - 03:36 AM