override << ?

This is a discussion on override << ? within the C++ Programming forums, part of the General Programming Boards category; Okay, how do I make for example show << to be equal to cout << Thank you in advance!...

  1. #1
    Registered User
    Join Date
    Oct 2001
    Posts
    104

    override << ?

    Okay, how do I make for example

    show <<

    to be equal to

    cout <<


    Thank you in advance!
    Ilia Yordanov,
    http://www.cpp-home.com ; C++ Resources

  2. #2
    Registered User
    Join Date
    Aug 2001
    Posts
    101
    Code:
    #include <iostream>
    
    using namespace std;
    
    int main()
    {
        ostream show = cout;
    
        show << "Hello world!" << endl;
    
        return 0;
    }
    - lmov

  3. #3
    zen
    zen is offline
    of Zen Hall zen's Avatar
    Join Date
    Aug 2001
    Posts
    1,007
    lmov's code won't work with compilers that use the standard C++ implementation (but will work with MSVC). If this doesn't work you could try this -

    Code:
    #include <iostream> 
    
    using namespace std;
    
    int main()
    {
    
    	ostream &show = cout;
    	   
    	show << "hello world\n";
    	return 0;
    }
    zen

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. cout << SunTradingLLC << "is looking for C++ Software Developers" << endl;
    By sun trading in forum Projects and Job Recruitment
    Replies: 1
    Last Post: 04-02-2008, 12:48 PM
  2. Overloading fstream's << and >> operators
    By VirtualAce in forum C++ Programming
    Replies: 2
    Last Post: 04-09-2007, 04:17 AM
  3. How do I override constructor in inheritance?
    By Loduwijk in forum C++ Programming
    Replies: 13
    Last Post: 03-24-2006, 09:36 AM
  4. cout << setiosflags(256L) << 123.123;
    By jochen123 in forum C++ Programming
    Replies: 2
    Last Post: 11-20-2002, 11:17 AM
  5. can't cout << hex << 'T'; what's wrong?
    By andre in forum C++ Programming
    Replies: 1
    Last Post: 03-19-2002, 07:53 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21