I am writing a program that creates an address book from a text file. I have to store some things in strings and some in enums. I think I have a handle on the enums, but certain things like the street address is giving me a hard time since it consists of several words and must be saved in one string variable. Also any numeric values should be stored as a string like the zip code. Relation is and
enum everything else a string.
here is an example of an entry on the text file
Bill Blanco 322-765-1788 6 30 1981 FRIEND 1667 N. Virginia Ave. Los Angeles CA 90029
Here is the code in question, any help would be appreciated.
Do you have a choice on the file format, or is it something which is given to you ready-made?
If you have the option, I would suggest the use of a delimiter (I like to use the tab character '\t') to separate individual fields, definitely there is a need for something to identify the streetAdress and city.
Also, in real-world data, some information may be missing, we may for example have just a first name and a phone number, or have full details but no date of birth etc. It depends what situations you need to handle.
the text file is not given and for the purpose of this assignment all fields are provided accordingly. I will look into a delimiter, thanks for the suggestion.
Having looked at this a bit more, I'm not quite sure what classes and types your program will be using. For the time being I've considered it as just using the local variables defined inside the function. Let's say we have an input file like this:
Bill Blanco 322-765-1788 6 30 1981 FRIEND 1667 N. Virginia Ave. Los Angeles CA 90029
for clarity, I'll mark where the tab characters are with a '#' character, but this isn't the real file
Bill#Blanco#322-765-1788#6 30 1981#FRIEND#1667 N. Virginia Ave.#Los Angeles#CA#90029
As an extra level of safety, you could also read the dob as a string using getline just like the other variables, and then if you like, use another stringstream to parse the integers within that dob string. When I say safety, I mean if for some reason the dob was invalid, as a string it would be ok, but as a set of integers, the input could fail.