|
-
Jan 31st, 2003, 09:48 AM
#1
Thread Starter
Junior Member
Stl Vectors and file handling
Hi,
Im trying to write the vector product to a file but im havin no luck this has worked for other objects in the past.
Thanks
Code:
vector<product_structure> product;
ofstream fout(filename,ios_base::binary);
if (!fout.is_open()) {
return false;
}
fout.write(reinterpret_cast<char*>(product),product.size * sizeof(product_structure));
fout.close();
c:\Documents and Settings\Administrator\Desktop\iBurn\cMain.h(53): error C2440: 'reinterpret_cast' : cannot convert from 'std::vector<_Ty,_Ax>' to 'char *'
with
[
_Ty=product_structure,
_Ax=std::allocator<product_structure>
]
-
Feb 8th, 2003, 06:22 PM
#2
A vector is a class, not a simple array. You may not do this, as it makes assumptions (probably wrong ones) about the internal layout of the vector.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|