I imagine that Array1 is of type Commodity, meaning your are treating Commodity as a POD type, and it is not. The Name field cannot be written like that, much less read back in.
For your read/write approach to work, you would need to change Name to a fixed-size char array, making Commodity a POD type.
If you don't want to do this (I wouldn't), the solution is more complex. The more straightforward approach would be to write in sequence the ID, Day, Month, Year and Price values, and after that, you write Name.c_str() including the terminating null char.
To simplify the operations, you could define a POD type:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
|
struct CommodityData
{
unsigned long long ID;
int Day;
int Month;
int Year;
double Price;
};
//And then use that in your Commodity class.
class Commodity
{
private:
CommodityData Data;
string Name;
...
};
| |
When you need to read, you would first read sizeof(CommodityData) right into Commodity::Data, and then I would use std::getline() to get the Name string inside Commodity::Name, using '\0' as the terminator char.