TheShadow1 wrote:
So something more like ...
struct Car
{
string rego;
string make;
string model;
string colour;
int cap;
int doors;
int costp;
int sellp;
}
/* Data file from previous article:
MJ914
Porsche
914-6
Irish_Green
2
2700
30000
40000
*/
struct Car
{
// Same as above
friend istream& operator>>(istream& input, Car& car_);
};
istream& operator>>(istream& input, Car& new_car)
{
getline(input, rego);
getline(input, make);
getline(input, model);
getline(input, colour);
input >> cap >> doors >> costp >> sellp;
return input;
}
Now to use this:
int main(void)
{
ifstream data_file("data_file.txt");
Car my_car;
// Input car from data file:
data_file >> my_car;
return EXIT_SUCCESS;
}
I suggest you also overload operator<< so you can
display the contents of a Car.
--
Thomas Matthews
C++ newsgroup welcome message:
http://www.slack.net/~shiva/welcome.txt
C++ Faq:
http://www.parashift.com/c++-faq-lite
C Faq:
http://www.eskimo.com/~scs/c-faq/top.html
alt.comp.lang.learn.c-c++ faq:
http://www.comeaucomputing.com/learn/faq/
Other sites:
http://www.josuttis.com -- C++ STL Library book