函数与sting对象
程序员文章站
2022-06-01 10:23:01
...
#include<iostream>
#include<string>
//#include<fstream>
//#include<math.h>
using namespace std;
const int SIZE = 5;
void display(const string sa[], int n);//传入sring组指针,大小n, 形参const string sa[] 即 const string *sa
int main()
{
string list[SIZE];
cout << "Enter your " << SIZE << " favorite astronomical sights:\n";
for (int i = 0;i < SIZE;i++)
{
cout << i + 1 << ": ";
getline(cin,list[i]);//输入一行字符串,存进string组
}
cout << "your list:\n";
display(list, SIZE);
cin.get();
return 0;
}
void display(const string sa[],int n)
{
for (int i = 0;i < n;i++)
{
cout << i + 1 << ": " << sa[i] << endl;//sa[i]即*(sa+i)
}
}
推荐阅读