For this program i have only used field separators from data files in shell script. But I am trying to use the standard library function ifstream() to read in from a data file. The only problem is I am getting the data like so
A:KT5:14:executive desk:
This is for a hash table, and I need to separate the values in the line for the data structure as well as the transaction type. I’ve been looking around the web and have not found much on field separators and what I have found was quite confusing.
The question then being, is there a way to set a field separator with the ifstream function or is there another standard library i/o function I should be using?
Thanks.
getline gives you the option to specify a delimiter. You can then read the input from a stream as a sequence of
stringseparated by_Delim:If this is uniformly structured data it might be useful to define a struct to contain it and implement
operator>>to load each instance from the stream, using the above function internal to the operator code.If you have to process multiple lines (so that newline is a record separator and : a field separator), load each line in turn into a
stringstreamusingbasic_istream::getline, and then postprocess the line into fields as shown.