1
0
forked from newde/homework
Files
homework/显示数组/showstr.cpp
newde 233b470060 上傳檔案到「显示数组」
用函数来实现显示数据
2026-02-06 21:26:51 -05:00

40 lines
638 B
C++

#include <iostream>
#include <string>
using namespace std;
struct Harem
{
int id;
int age;
string name;
};
void show(const Harem &hm) // ⭐ 类型必须写
{
cout <<" " <<hm.id <<" "<< hm.age <<" "<< hm.name << endl;
// cout << "ID:" << hm.id
// << " AGE: " << hm.age
// << " NAME: " << hm.name
// << endl;
}
int main()
{
Harem people[] =
{
{1001, 18, "佐伊"},
{1002, 19, "寒冰"},
{1003, 17, "女警"},
{1004, 18, "盖伦"}
};
int size = sizeof(people) / sizeof(people[0]);
for (int i = 0 ; i< size ; i++ )
{
show(people[i]);
}
return 0;
}