Write to a binary file?

Posted by rick irby on Stack Overflow See other posts from Stack Overflow or by rick irby
Published on 2010-04-07T20:53:48Z Indexed on 2010/04/07 21:03 UTC
Read the original article Hit count: 195

Filed under:
|
|
|
|

Here is data structure w/ variables:

struct Part_record
{
    char id_no[3];
    int qoh;
    string desc;
    double price:
};
---
(Using "cin" to input data)
---
Part_record null_part = {"  ", 0,"                         ",0.0};
---
---
file.seekg( -(long)sizeof(Part_record), ios::cur);
file.write( ( char *)&part, sizeof(Part_record) );

The three variables, qoh, Id_no & price, write out correctly, but the "desc" variable is not right. Do I need to initialize Part_record some other way? It should be 20 characters in length.

If you have enough info here, pls share your advice,thanks.

© Stack Overflow or respective owner

Related posts about c++

Related posts about data