iterator_traits::value_type on back_insert_iterator - returns void
 
Hello,
My Requirement is
1. Copy data from iterator to an array ( array should be created
dynamically within the function based on       data_type of the data
held by the iterator /container. )
2. Copy data from array into iterator ( array should be created
dynamically within the function based on       data_type of the data
held by the iterator /container. )
Implementation
-----------------------
//copies data from begin to end of container to array.
template <class T>
void writeiter( T& iter1, T& iter2)
{
   int t2= iter2 -iter1;
   cout <<t2<<endl;
   iterator_traits<T>::value_type *twrite= new
iterator_traits<T>::value_type[t2];
   std::copy(iter1,iter2,twrite);
}
//copies data from array to iter (back_insert_iterator)
template <class T> void readiter( T& iter, int len)
{
   //This line does not compile since return is a void.
   iterator_traits<T>::value_type *tread= new
iterator_traits<T>::value_type[len];    for (int i=0; i<len;++i)
    tread[i] = i;
    std::copy(tread, tread+ len,iter );
}
int main()
{
  vector <int> v1;
  int len=5;
 back_insert_iterator< vector<int> > v1back(v1);
 readiter(v1back,len); //Does not work - the function does not compile
 vector<int>::iterator vbdir1=v1.begin();
 vector<int>::iterator vbdir2=v1.end();
 writeiter(vbdir1,vbdir2); //works good
}
The readiter function does not compile since a
iterator_trait::value_type of back_insert_iterator's returns void.
what i would need is to get the datatype of the container which is INT
held by the back_insert_iterator. My assumption was that i would get
the iterator_traits of back_insert_iterator from function readiter ,
which would later be used to create an array or a array of pointers.
Any help appreciated?
Thanks
Anish