上傳檔案到「显示数组」
用函数来实现显示数据
This commit is contained in:
39
显示数组/showstr.cpp
Normal file
39
显示数组/showstr.cpp
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
#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;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user