Output data to file using for_each C++?
<p>I want to use the for_each function to out an object to file, it sounds crazy but is it possible?. I have tried myself but it seems not to work. Here are what I have done so far:</p>

<pre><code>//Sterling.h


        template&lt;class T&gt;
void myfn(const T&amp; t, const iostream&amp; io = cout)
{
        io &lt;&lt; t;
}

template&lt;class T&gt;
class fefnptr{
        public:
                void operator()(const T&amp; t, const iostream&amp; io = cout) const
                {
                        io &lt;&lt; t;
                }
};

class Sterling{
// also implement the operator&lt;&lt; and other functions in Sterling.cpp
};

//main.cpp
int main(){
        fstream fp("test",fstream::out);
        if(!fp) cerr &lt;&lt; "Unable to open the file\n";
        else
        {
                for_each(arr,arr+5,fefnptr&lt;Sterling&gt;(,fp)); // the syntax here is wrong and
I know that but I just want to put the fp as an parameter to output the object to the file
        }
        fp.close();
return 1;
}
</code></pre>

<p>And it turns out the error(of course I know what it is) missing parameter ( it is the object that I want to output to the file). So any idea for using for_each to output object to file?
Thanks in advance!</p>
