I have a std::vector<int>
and I want serialize it. For this purpose I am trying to use a std::stringstream
vector<int> v;
v.resize(10);
for (int i=0;i<10;i++)
v[i]=i;
stringstream ss (stringstream::in | stringstream::out |stringstream::binary);
However when I copy the vector to the stringstream this copy it as character
ostream_iterator<int> it(ss);
copy(v.begin(),v.end(),it);
the value that inserted to buffer(_Strbuf) is "123456789"
I sucssesed to write a workaround solution
for (int i=1;i<10;i++)
ss.write((char*)&p[i],sizeof(int));
I want to do it something like first way by using std function like copy
thanks Herzl