知识库

C++语言开发示例:20. 前五个

2025-02-01 20:31:27 李腾 1 次阅读

topfive.cpp

#include <iostream>
#include <string>
using namespace std;

const int SIZE = 5;
void display(const string sa[], int n);

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]);
    }
    cout << "Your list:\n";
    display(list, SIZE);

    return 0;
}

void display(const string sa[], int n)
{
    for (int i = 0; i < n; i++)
        cout << i + 1 << ": " << sa[i] << endl;
}
转载请注明转自www.hylab.cn,原文地址:C++语言开发示例:20. 前五个

评论 (0)

登录后发表评论

暂无评论,快来发表第一条评论吧!