TM> And what you want to write is:
TM> Person aPerson;
TM> iasciistream inFile("filename");
TM> if (inFile >> aPerson)
TM> // reading was a success, use aPerson
TM> else
TM> // oops
TM> iasciistream is a class you have to derive from istream. Overload the
TM> operator>> for string, int, double and maybe other types according to
TM> your file structure (input operations have to eat the commas, string
No, you don't need to create your own class. Just have a friend to Person
who is the overloaded operator>>.
TM> iostream &operator>>(iostream &ias, Person &aPerson)
TM> {
TM> return ias >> aPerson.Id
TM> >> aPerson.FirstName
TM> >> aPerson.LastName
TM> >> aPerson.aString
TM> >> aPerson.anInt
TM> >> aPerson.anotherInt
TM> >> aPerson.aDouble;
TM> }
There ya go - that's all that's needed.
If it comes in from a string, a file, a modem, whatever, this will read in
the strings. However, his example was much more complicated than this,
requiring some parsing of quotes and commas.
--- Maximus/2 3.01
---------------
* Origin: Tanktalus' Tower BBS (1:250/102)
|