i need help with string streams
I'm still putting finshing touches on this Phonebook Entry program I am working on. I am using a data file that will keep the data in a formatted style so that the user can look at the .txt file and be able to find information easily without having to load the program every time. So, essentially, I am outputing to a file in a formated form>>>
Code:
Name: John Doe
Home Phone Number: 333-3333
Cell Phone Number: 444-4444
Address: 123 Hello Dr.
Now when the program opens a file, it uses getline for every line and sets each one to a separate string. Everything is fine, except that I need to get the actual data out of the string.
Code:
Ex.
(GET LINE FROM FILE. SET TO STRING)
Name: John Doe << this is the string
I want to get data out of the string.
John Doe << i want this data out of the string above.
I realize i need to use string streams, but I don't know how to skip the Name: and the whitespace to get to John Doe.
Here is my getline function, and my attempt with string streams.
Code:
/*******************************/
/**** Phonebook::GetEntries ****/
/*******************************/
void Phonebook::GetEntries(fstream &fFile)
{
stringstream s;
char test1;
Entry temp;
if(get(fFile,test1)==NULL)
{
return;
}
else
{
while(getline(fFile,temp.name))
{
getline(fFile,temp.cnumber);
getline(fFile,temp.hnumber);
getline(fFile,temp.address);
s.str(temp.name);
s >> "Name:\t\t\t" >> temp.name;
s.str(temp.cnumber);
s >> "Cell Phone Number:\t" >> temp.cnumber;
s.str(temp.hnumber);
s >> "Cell Phone Number:\t" >> temp.hnumber;
s.str(temp.address);
s >> "Address:\t\t">> temp.address;
vEntries.push_back(temp);
}
}
}