定义一个User结构体

d: 一个数字,每个用户不同的id
email: email地址,一般网站的用户允许以email地址登录
gender: 性别,男or女
QQ: QQ号码
写一个函数,在User数组中查找某个id的User
函数描述:
User* find (User* all, int n, int id);
其中,
all: 输入一个User数组
n : 数组长度
id: 待查找的id

#include<iostream>
#include<string>
using namespace std;
struct User {
    int id;
    string email;
    string gender;
    long int qq;
};
User* find(User* all, int n, int id)
{
    for (int i = 0; i < n; i++)
    {
        if (all[i].id == id)
        {
            cout << all[i].id << "  " << all[i].email << "  " << all[i].gender << "  " << all[i].qq << "  " << endl;
        }
    }return 0;
}
int main()
{struct User s[3]={{123,"qwe","",147258},
                   {456,"asd","",147369},
                   {789,"zxc","",258369}
                  };
find(s, 3, 123);
return 0;
}

 

posted @ 2023-04-18 20:33  酥饼馅红豆沙  阅读(33)  评论(0编辑  收藏  举报