Can C++ do this???

Hi there,
I'm learning class in C++
I wonder how (if it is possible) to write something like
 
  cout << OwnClass ;       //like: OwnClass.PrintFunction(); 


Yes. You need to overload operator<<:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <iostream>

struct foo {};

std::ostream& operator<<(std::ostream& out, const foo& value)
{
    out << "Hi, I am outputting foo!";
    return out;
}

int main()
{
    foo var;
    std::cout << var;
}
thanx a lot for the quick answer!!! So I need to learn operator overloading ;-)
Topic archived. No new replies allowed.