user2756494
user2756494

Reputation: 273

overload cout without any user defined things in main in c++

can i overload cout? just use the same code in main here

using namespace std;
int main() {

     cout << “overload" <<endl;
     return 0;
}

is it possible to overload << here? For example let the program prints "overload operator" instead of "overload"?

Upvotes: 1

Views: 165

Answers (1)

micheal.yxd
micheal.yxd

Reputation: 128

cout is just an object in namespace std.

If your "overload" means using the same code to do other things, you can create a namespace on your own, create an instance named cout, then override the << operator.

Upvotes: 1

Related Questions