C++ Exercise for the Day

|

C++ exercise for the day. Write the header file (say "util.h") needed to define (not implement) operator<< for a vector of integers. Basically, the following code should compile and work in all situations:

#include "util.h"

// ... Some time later in a function or method ...
{
    std::vector<int> v;
    v.push_back(1);
    v.push_back(2);
    v.push_back(3);
    std::cout << "My vector: " << v << std::endl;
}

Maybe I'm just dumb, but it took me the better part of a whole day to figure out how to do this correctly. My guess is that if you aren't 100% sure of the answer, you will be surprised by it. Answer to come in a day or two.

blog comments powered by Disqus

About this Entry

This page contains a single entry by Dave published on February 16, 2005 8:32 PM.

I-GO was the previous entry in this blog.

Go Tiger is the next entry in this blog.

Find recent content on the main index or look in the archives to find all content.

Links

Powered by Movable Type 4.1