![]() |
| | #1 |
| Registered User Join Date: Dec 2002
Posts: 6
| substituting cout I have the following question: I would like to use another 'command' to output data on the screen. e.g. instead of cout << "abc"; i would like to use my_own_cout << "abc"; I have tried to declare it: ostream my_own_cout; But it didn't work. Why is that so? How to make a 'substitute' for cout? TNX |
| JerryL_MB is offline |
| | #2 |
| Registered User Join Date: Sep 2002
Posts: 1,640
| I think macro's are what you're looking for, Don't know exactly how to use it with 'cout' though |
| Travis Dane is offline |
| | #3 |
| Guest
Posts: n/a
| #define cout my_own_cheese |
| | #4 | |
| Programming Sex-God Join Date: Nov 2002
Posts: 1,078
| Quote:
#define my_own_cheese cout Still, Sang-drax is right, #defines are evil! | |
| Polymorphic OOP is offline |
| | #5 |
| and the hat of marbles Join Date: May 2002 Location: Göteborg, Sweden
Posts: 2,038
|
__________________ Last edited by Sang-drax : Tomorrow at 02:21 AM. Reason: Time travelling |
| Sang-drax is offline |
| | #6 |
| Registered User Join Date: Dec 2002
Posts: 6
| Thanx sang-drax, the code is working. But can someone explain it to me a little bit? Code: std::ostream& my_own_cout = cout; Code: ostream my_own_cout; or std::ostream my_own_cout; Thank you in advance! |
| JerryL_MB is offline |
| | #7 |
| Registered User Join Date: Sep 2002
Posts: 272
| >std::ostream& my_own_cout = cout; Is creating a reference (alias) to the original cout. my_own_cout isn't a seperate object. If you really want a seperate ostream object you could do - ostream my_own_cout(cout.rdbuf()); Which will point your ostream streambuf pointer at the same one cout uses. Or if that's not enough you could derive you're own streambuf class an implement all the system calls, etc and assign it to your ostream object.
__________________ Joe |
| JoeSixpack is offline |
| | #8 |
| Registered User Join Date: Nov 2001
Posts: 330
| ~ cout is the standard output device, so you can access it directly, under a different name by using a reference. To declare an ostream object you have to pass in a streambuf pointer, I don't think it has a default constructor. EDIT: as was already said... hehe =) |
| rmullen3 is offline |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Wiki FAQ | dwks | General Discussions | 192 | 04-29-2008 01:17 PM |
| Redirect FAQ... | Queatrix | General Discussions | 21 | 05-21-2007 04:48 PM |
| printf vs cout | RyeDunn | C++ Programming | 5 | 07-09-2002 04:26 PM |
| FAQ cout | evilmonkey | FAQ Board | 1 | 10-07-2001 11:32 AM |
| What's wrong with Micorsoft Visual C++? | knave | C++ Programming | 9 | 10-04-2001 08:02 AM |