I'm making a very basic email server and I need a function to show me how many emails the inbox of a user has. Each email sent has the word "#email" at the top so I'm using it as a keyword do count how many emails, but is not working and I don't know why. Can someone please tell me what is wrong or put me in the right direction?? thanks
int GetInboxCount(std::string username)
{
std::ifstream email(username + "-inbox.txt"); //opens the inbox file
std::string item;
int count = 0;
while(!email.eof()) //read the file until the end
{
email >> item;
if(item == "#email") //search for the word #email that is at the top of every email in the inbox
{
++count;
}
}
email.close();
return count; //it should return the numbers of emails