Joe of Loath
Joe of Loath

Reputation: 169

C++ send output of function to cout

So I have a function called isEmpty() to check if a specified array has been filled with variables.

    bool isEmpty() const;

This is:

bool Array::isEmpty() const
{
   if(elemData == NULL)
        return true;
   else
        return false;
}

I'm trying to call it in my main.cpp so that I can send the output of isEmpty to cout, but I can't work out how to call it. I've tried a bunch of different methods but I feel I'm shooting in the dark, and I can't find any similar examples elsewhere.

How can I do this?

Upvotes: 0

Views: 580

Answers (2)

Kiril Kirov
Kiril Kirov

Reputation: 38173

You can directly use

std::cout << your_container.isEmpty();

Or you can even output it like:

std::cout << std::boolalpha << your_container.isEmpty();

Upvotes: 3

user3416290
user3416290

Reputation:

You mean this?:

cout << array.isEmpty();

Booleans can be printed by default. In fact, every class you create can print out values with cout, but only if you previously define both ostream and istream operators for this class.

Upvotes: 2

Related Questions