🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

1 total messages Started by Mark Rafter Wed, 15 Oct 1986 16:15
partial solution to cout << 'a' producing 97
#357
Author: Mark Rafter
Date: Wed, 15 Oct 1986 16:15
29 lines
1380 bytes
If you add the following (Steve Rumsby's idea):

	ostream& put(char);		// put('a') writes a
	ostream& operator<<(const char &c){ return this->put(c);}

to the class ostream BEFORE the declaration of the operator

	ostream& operator<<(int a) { return *this<<long(a); }

and delete the original declaration of put(char) , then the program:

	#include <stream.h>
	main()
	{
		char b = 'b';
		cout << char('a') << b;
	}

will output ``ab'' rather than ``9798''. However there are the following
(related) quirks:

	1	the order of the declarations is important
	2	the new << operator must be a member of ostream

I cannot find any justification for these two points in the C++ book -
is there any?
		----------------------------------
Mark Rafter, Computer Science, Warwick Univ, Coventry CV4 7AL, ENGLAND
	..!ukc!warwick!rafter	+44 203 523364
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads