From: Hans-Bernhard Broeker Newsgroups: comp.os.msdos.djgpp Subject: Re: Question about the puts command in C++ Date: 15 Feb 2000 13:17:57 GMT Organization: Aachen University of Technology (RWTH) Lines: 31 Distribution: world Message-ID: <88bjm5$qrk$1@nets3.rz.RWTH-Aachen.DE> References: NNTP-Posting-Host: acp3bf.physik.rwth-aachen.de X-Trace: nets3.rz.RWTH-Aachen.DE 950620677 27508 137.226.32.75 (15 Feb 2000 13:17:57 GMT) X-Complaints-To: abuse AT rwth-aachen DOT de NNTP-Posting-Date: 15 Feb 2000 13:17:57 GMT User-Agent: tin/1.4-19991113 ("No Labels") (UNIX) (Linux/2.0.0 (i586)) Originator: broeker@ To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com Harry Hiratos wrote: > I have written a program which includes the following lines: > Employee Sarah; > cout << "Her salary is : " << Sarah.getMessage(); > where Sarah is an object of class Employee. The function getMessage is > defined inline as follows: > char getMessage() { puts( message ); } At the very base of your problem, this routine is incorrect. It does not do what its name and usage suggests it will. A routine to be used in the way you use 'Sara.getMessage()' above would have to return a string or char *, which in turn contains the message string. It should definitely *not* generate any direct output, itself. I.e. the correct definition of 'getMessage()' would probably have been: char *getMessage() { return message; } > When I run this program, it prints the words "Her salary is : " on the line > immediately after the output of getMessage, instead of before it on the same > line. That's a second-order consequence. puts() and cout come from two separate families of output functions, that don't mix well. But as I said, the real problem is that getMessage shouldn't have called puts() at all, in the first place. -- Hans-Bernhard Broeker (broeker AT physik DOT rwth-aachen DOT de) Even if all the snow were burnt, ashes would remain.