My if statement will seem confusing but this is what I was doing. Is there a way I can break down my string DOB into three strings i.e. string DAY, string MONTH string YEAR. That seems to be the only way to handle this. Unless I iterate through my whole and break down the DOB variable into int's using string stream. I think it would be easier on the computer to just convert one string (time()) instead.
Or maybe converting the string stream below on line (9,10,11) to a solid string and comparing that way. However that method is giving me issues too.
Code:
void addressbook::GenBirthdayCards()
{
bool found = false;
time_t t = time(0); // get time now
struct tm *now = localtime(&t); //date will read 2014120 meaning 2014-1-20 but will have no punctuations.
std::stringstream year(now->tm_year+1900);
std::stringstream month(now->tm_mon+1);
std::stringstream day(now->tm_mday);
for (auto it = Mylist.begin(); it!= Mylist.end();++it)
{
if (month == it->MONTH && //comparing the computers current date to that of the nodes
day == it->DAY &&
year == it->YEAR) //YEAR DAY and MONTH are just examples
{ //if it matches, a card is generated and reads:
std::cout << "Dear " << it->FirstName << " " << it->LastName << ": " << std::endl;
std::cout << std::endl << std::endl;
std::cout << "May your Birthday be the best yet and we wish you more to come\n";
std::cout << std::endl << std::endl;
std::cout << "Respectfully,\n";
std::cout << "Drew\n";
found=true;
}
}
if (!found) {
std::cout<<"No Birthdays are today."<<std::endl;
}
}
Code:
struct MyaddressBook {
std::string firstName;
std::string lastName;
std::string address;
std::string aniversary;
std::string DOB;
};
class addressbook {
private:
std::list<MyaddressBook> Mylist;
public:
addressbook();
void addContact(MyaddressBook&);
void readfile(std::ifstream&,MyaddressBook&);
void updateFile(MyaddressBook&);
void EditNameOrDate();
void PrintAddressBook();
void GenBirthdayCards();
void GenAnnCard();
void deleteContact(std::string);
void sortContacts();
void ExitProgram();
};