Can somebody tell me how read in a text file like this? I am using a combination of string, int, and char variables. Normally, when I have read in files like this in the past, I have not used strings, just char arrays.
Example Data that I'm reading in from a text file where each line has the following format:
string name; char flag; string tag; string contactInfo; int count; string message%
Inigo Montoya;e;email;fiveFingeredMan@gmail.com;0;
Bruce Smith;m;messenger;SourPatchSmith;0;
Dolly Llama;e;email;DramaLlama@gmail.com;1;Hello, this is a reminder that you have an appointment Monday at 3pm. Please give at least 24 hours notice to cancel.%
Mark LaRusso;e;text;251-333-4562;1;What time is the soccer game?%
Martha Epp;m;messenger;MeppHead;2;Thank you, Thomas. I am available Wednesday 8-9:30 am or 11:30-1:30 pm. Thursday, I'm open any time before 3 pm.%Thanks Thomas, that will work perfectly. See you then.%
Jane Lawson;e;email;JaneAndTarzan@gmail.com;1;Good afternoon, hope this message finds you well. This is just a reminder that we have an appointment tomorrow morning.%
Normally, this is how I have approached this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
|
ifstream inFile;
char name[30];
char flag; // single character
char tag[15];
char contactInfo[100];
int count = 0;
char message[1000];
// read in first line
inFile.get(name, 30, ';');
while(!inFile.eof())
{
inFile.ignore(30, ';');
inFile >> flag;
inFile.ignore(100, ';');
inFile.get(tag, 15, ';');
inFile.ignore(15, ';');
inFile.get(contactInfo, 100, ';');
inFile.ignore(100, ';');
inFile >> count;
inFile.ignore(100, ';');
// so on and so forth
// I have conditional statements based on my flag ('e', 't', 'm')
// and a separate set of conditions based on the count, if 0, no messages
// if count != 0, read in messages separated by '%' as delimeter
}
|