Errata for 3rd/13th printing of The C++ Programming Language

Errata for Bjarne Stroustrup: The C++ Programming Language (special edition), Addison-Wesley, 2000. ISBN0-201-70073-5. Errata for the 3rd printing yielding the 4th printing. Also for the 12th printing of "The C++ Programming Language (3rd edition)" yielding the 13th printing.

Errors and Clarifications


Chapter 14:

pg 380 after the first paragraph add: "The clone() function is used to allocate a copy of an exception on free store. This copy will survive the exception handler's cleanup of local variables."

Chapter 17:

pg 493 the argument to bitset'c onstructor requires a conversion to string:

	bitset< 10> b4(string("1010101010")); 		// 1010101010
	bitset< 10> b5(string("10110111011110",4)); 	// 0111011110
	bitset< 10> b6(string("10110111011110",2,8)); 	// 0011011101

	bitset< 10> b7(string("n0g00d"));			// invalid_argument thrown
	bitset< 10> b8 = string("n0g00d");			// error: no string to bitset conversion

Chapter 18:

pg 524 s/operator()(const Club&)/operator()(const Club&) const/

Chapter 20:

pg 596 add to class basic_string:

	void clear();	// erase all characters

Chapter 21:

pg 633 s/smanip& m)/const smanip& m)/

pg 635 s/<< d << endl;/<< 1.41421 << endl;/

Appendix D:

pg 895 s/&s[pos]/s.begin()+pos/

pg 912 s/Month(x.tm_mon)+1/Month(x.tm_mon+1)/

pg 915 s/(f.put( ... .failed)/(f.put( ... .failed())/

pg 916 s/Month(x.tm_mon)+1/Month(x.tm_mon+1)/

pg 916 s/std::time_get< Ch>/std::time_get< Ch,In>/

pg 917 a better getval():

	template< class Ch, class In>
	In Date_in< Ch,In>::getval(In b, In e, ios_base& s, ios_base::iostate& r, int* v, Vtype* res) const
		// read part of Date: number, day_of_week, or month. Skip whitespace and punctuation.
	{
		const ctype< Ch>& ct = use_facet< ctype< Ch> >(s.getloc());  // ctype is defined in D.4.5
		Ch c;

		*res = novalue;	// no value found

		for (;;) {	// skip whitespace and punctuation
			if (b == e) return e;
			c = *b;
			if (!(ct.is(ctype_base::space,c) || ct.is(ctype_base::punct,c))) break;
			++b;		
		}

		if (ct.is(ctype_base::digit,c)) {     //  read integer without regard for numpunct
			int i = 0;

	    		do {	// turn digit from arbitrary character set into decimal value:
				static char const digits[] = "0123456789";
				i = i*10 + find(digits,digits+10,ct.narrow(c,' '))-digits;
				c = *++b;
			} while (ct.is(ctype_base::digit,c));

			*v = i;
			*res = unknown;	// an integer, but we don't know what it represents
			return b;
		}

		if (ct.is(ctype_base::alpha,c)) {   // look for name of month or day of week
			basic_string< Ch> str;
			while (ct.is(ctype_base::alpha,c)) {	// read characters into string
				str += c;
				if (++b == e) break;
				c = *b;
			}

			tm t;
			basic_stringstream< Ch> ss(str);
			typedef istreambuf_iterator< Ch> SI;	// iterator type for ss' buffer
			get_monthname(ss.rdbuf(),SI(),s,r,&t);	// read from in-memory stream buffer
			if ((r&(ios_base::badbit|ios_base::failbit))==0) {
				*v= t.tm_mon;
				*res = month;
				r = 0;
				return b;
			}

			r = 0;	// clear state before trying to read a second time
			get_weekday(ss.rdbuf(),SI(),s,r,&t);	// read from in-memory stream buffer
			if ((r&ios_base::badbit)==0) {
				*v = t.tm_wday;
				*res = dayofweek;
				r = 0;
				return b;
			}
		}
		r |= ios_base::failbit;
		return b;
	}

pg 919 replace

	template< class Ch, class In = istreambuf_iterator< Ch> >
	In Date_in::do_get_date(
by
	template< class Ch, class In>
	 In Date_in< Ch,In>::do_get_date(

pg 922 a better count_spaces():

	int count_spaces(const string& s, const locale& loc)
	{
		const ctype< char>& ct = use_facet< ctype< char> >(loc);
		int i = 0;
		for(string::const_iterator p = s.begin(); p != s.end(); ++p)
			if (ct.is(ctype_base::space,*p)) ++i;	// whitespace as defined by ct
		return i;
	}

pg 922 s/loc.is(space|punct,c)/ct.is(ctype_base::space|ctype_base::punct,c)/

pg 922 s/std::ctype/std::ctype< Ch>/

pg 923 s/std::ctype/std::ctype< Ch>/

Typos

Chapter 14:

pg 365 s/program now shrinks/function now shrinks/

Appendix D:

pg 892 s/_byname locale/_byname facet/