To load from a file you use std::ifstream
but your bigger problem is how do you know what shape you are loading?
since some shapes can require more data than others you don't know how to load the file
this is why I suggested using an ascii file so aswell as the data
you load the information to know
1 - how many shapes you have
2 - what is the current shape to load & therefore how much data
so then you could load the line of data or name depending upon your choice
check the name cast the shape * pointer and then load the remaining data.
so for a shape I would add the following methods
static std::string get_name();
bool is_my_name(std::string &name);
bool load(std::string &line);
if you load the file as std::ios::i
you can use get_line() until you get an empty line
check the line for the first word matching a shape_id
then
Shape * ps = 0;
//chop the 1st keyword
std::string shape_id = get_shape_id(line);
if(shape_id == square::get_name())
{
square p_sq = new square();
p_sq->load(line)
ps = p_sq;
}
else if(shape_id == circle::get_name())
{
circle p_cc = new circle();
p_cc->load(line);
ps = p_cc;
}
if(ps != 0)
{
data.push_back(ps);
}
///...
P.S. you probably don't need to post the entire code each time unless you have a bug
I have managed to sort out saving to a file, however I have …