1 // C++函数和类 13-函数与string对象.cpp: 定义控制台应用程序的入口点。
2 //
3
4 #include "stdafx.h"
5 #include <iostream>
6 #include <limits>
7 #include <array>
8 #include <math.h>
9 #include <string>
10 using namespace std;
11 void fill_games(string name[], int n);
12 void print_games(const string name[], int n);
13
14 int main()
15 {
16 const int size = 5;
17 cout << "请输入" << size << "个你喜欢的游戏名称:"<<endl;
18 string gameNames[size] = {};
19 fill_games(gameNames, size);
20 print_games(gameNames,size);
21 return 0;
22 }
23
24 void fill_games(string name[], int n)
25 {
26
27 for (int i = 0; i < n; i++)
28 {
29 getline(cin, name[i]);
30 }
31 }
32 void print_games(const string name[], int n)
33 {
34 for (int i = 0; i < n; i++)
35 {
36 cout << i + 1 << ":"<<name[i] << endl;
37 }
38 }