Reading data from a text file
I am using this struct to store data from a text file
the file uses tags to determine what data member each line belongs to like this : (CODE_TAG)(DATA)
short unsigned int Number;
long double Amount;
Each line in the file is saved to a std::string and the tag is extracted to determine which data member the line should be saved to.
I'm just not sure of the best method to do this. I could use a bunch of if...then statements like this
read line into std::string temp;
extract first part of line into std::string Code_Tag;
extract the rest of the line into std::string Data;
using Code_Tag, determine what Data is and save it to the approperiate sItem member;
} while (NOT EOF)
But I don't like the way that looks, and it seems like there would be too much over head with all the 'if...then' tests.
if (Code_Tag == "TRNTYPE") Item.Type = data;
if (Code_Tag == "NAME") Item.Name = data;
I could use a switch...case statement but VC Toolkit 2003 will not let me switch a std::string.
I have also tried enumerating the code tags like this
and just switching that, but then I have to convert each line from the std::string to the enum value. This seems to be just as much of a pain as the first idea.
typedef enum CODE_TAGS
TAG_START = 0xff01,
TAG_TYPE = 0xff02,
TAG_DATE = 0xff03,
TAG_AMOUNT = 0xff04,
TAG_NAME = 0xff05,
TAG_MEMO = 0xff06,
TAG_ITEMNUM = 0xff07,
TAG_END = 0xff08
Any thoughts / ideas on what the best way would be to go about doing this?