Visual c++ 在文本文件中找不到两个名称

Visual c++ 在文本文件中找不到两个名称,visual-c++,Visual C++,我有一个包含1000行的文本文件。第一行看起来像“1雅各布·艾米丽”。第2-1000行就是这样。我需要编写一个程序,调用一个函数,搜索男性姓名和女性姓名 我的输出应该如下所示: 例如,如果用户输入名称“Justice”,则程序应输出: Justice is ranked 406 in popularity among boys. Justice is ranked 497 in popularity among girls. Walter is ranked 366 in popularity

我有一个包含1000行的文本文件。第一行看起来像“1雅各布·艾米丽”。第2-1000行就是这样。我需要编写一个程序,调用一个函数,搜索男性姓名和女性姓名

我的输出应该如下所示:

例如,如果用户输入名称“Justice”,则程序应输出:

Justice is ranked 406 in popularity among boys.
Justice is ranked 497 in popularity among girls.
Walter is ranked 366 in popularity among boys.
Walter is not ranked among the top 1000 girl names.
如果用户输入名称“Walter”,则程序应输出:

Justice is ranked 406 in popularity among boys.
Justice is ranked 497 in popularity among girls.
Walter is ranked 366 in popularity among boys.
Walter is not ranked among the top 1000 girl names.
以下是我搜索姓名的功能:

void name_search (string name)
{
    int rank;
    string male, female; 
    ifstream infile;
    bool male_found = false, female_found = false;


    infile.open ("babynames2004.txt");

    if (infile.fail())
    {
        cout << "The file was corrupt.\n";
    }


    while (!infile.eof() && male_found == false && female_found == false)
    {
        infile >> rank >> male >> female;

        if (name == male)
            male_found=true;
        else if (name == female)
            female_found=true;
    }

    if(male_found == true && female_found != true)
    {
        cout << name << " is ranked " << rank << " in popularity among boys.\n";
        cout << name << " is not ranked among the top 1000 girl names.\n";
    }
    else if (male_found != true && female_found == true)
    {
        cout << name << " is not ranked among the top 1000 boys names.\n";
        cout << name << " is ranked " << rank << " in popularity among girls.\n";
    }
    else if (male_found == true && female_found == true)
    {
        cout << name << " is ranked " << rank << " in popularity among boys.\n";
        cout << name << " is ranked " << rank << " in popularity among girls.\n";
    }
    else if (male_found != true && female_found != true)
    {
        cout << name << " is not ranked among the top 1000 boys names.\n";
        cout << name << " is not ranked among the top 1000 girl names.\n";
    }

    infile.close();
}
2004年最受欢迎的男婴和女婴名字

输入要搜索的名称:Jacob 雅各布在男孩中的受欢迎程度排名第一。 雅各布没有跻身前1000名女孩之列

是否要再次运行此程序?(是或否) Y 这个程序允许您从1000个名字的列表中搜索名字的排名 2004年最受欢迎的男婴和女婴名字

输入要搜索的名称:Emily 艾米丽没有跻身前1000名男孩之列。 艾米丽在女孩中的受欢迎程度排名第一

是否要再次运行此程序?(是或否) Y 这个程序允许您从1000个名字的列表中搜索名字的排名 2004年最受欢迎的男婴和女婴名字

输入要搜索的名称:Jordan 乔丹在男孩中的受欢迎程度排在第43位。 乔丹没有跻身前1000名女孩之列

是否要再次运行此程序?(是或否)

Jordan这个名字出现在第43行(男性)和第70行(女性)。问题似乎在于,当输出错误时,男性姓名和女性姓名同时出现。顺便说一下,这是一个编程类的作业,这个类就像一个游戏。这与实际学习编程无关,所以我只限于课堂上教授的基本结构


有人能告诉我为什么吗

除了“你能为我做我的工作”之外,你还有什么问题。让用户输入一个名称。2.创建附加到文本文件并搜索与男性姓名、女性姓名或两者匹配的姓名的函数。告诉用户该名字是否在前1000名婴儿名字中,包括男性、女性、两者,或者两者都不是。我已经为此工作了几个小时,并在cplusplus上寻求帮助。这门课是个笑话。我很有限,这使得代码很难创建。几个小时前,我会使用其他结构来解决这个问题,但我基本上是不被允许的,因为更高级的东西在课堂上没有涉及。