I've been trying various methods, but none of them is giving me the output I want, or it terminates the program because of an error.
This is what I have so far:
Code:
string ms;
int s1, f1, hold, f2hold, f1hold, length, i=0;
string f2, s2;
ms = ">From: Jim\nTo: Lauren\nSubject: Zoo\nMessage: I was just wondering if you were going to the zoo today.
Gimmie an email please. \nTime: Sat Apr 12 11:32:09 2003>From: Lem\nTo: Jim\nSubject: Re:Zoo\n
Message: Nah, not going today. \nTime: Sat Apr 12 11:32:09 2003";
// string is all one line
while(ms.find("From:")){
length = ms.size();
f1 = ms.find("From:");
hold = ms.find("\nTo:");
f1hold = hold - f1;
f2.assign( ms, f1, f1hold);
s1 = ms.find("Subject");
hold = ms.find("\nMessage:");
f2hold = hold - s1;
s2.assign( ms, s1, f2hold);
cout << ++i << ": " << f2 << " " << s2 << endl;;
ms.erase (hold, length);
}
What I want it to do is search for the From and Subject, print it out, then delete the section it's already checked, and begin the process again.
So I want the output to be:
1. From: Jim Subject: Zoo
2. From: Lem Subject: Re:Zoo
I tried the .npos method, but I wasn't able to make it work.
cheers,
Jim