Results 1 to 2 of 2

Thread: Stl Vectors and file handling

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Nov 2002
    Location
    Left past the postbox
    Posts
    30

    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>
            ]

  2. #2
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    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
  •  



Click Here to Expand Forum to Full Width