我正在制作一个非常基本的电子邮件服务器,我需要一个功能来向我显示用户收件箱中有多少封电子邮件。发送的每封电子邮件顶部都有“#email”字样,因此我将其用作关键字确实计算了多少封电子邮件,但是无法正常工作,我不知道为什么。有人可以告诉我有什么问题或者让我走向正确的方向吗? 感谢
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