adding a counting variable to an ostream overload

75 views Asked by At

I was wondering if there was anyway to overload the ostream with a counting variable for instance

ostream& operator << (ostream& out, TYPE t,int i);

I need the int to help output part of an array and it would be a lot easier if I could just send an int through the overload

1

There are 1 answers

2
Seagull On

You may use

struct TypeOut
{
    TYPE _t;
    int _i;
};

and write function ostream& operator << (ostream& out, TypeOut t);