我正在创建一个函数,其中包含6个值(3个字符串,3个整数),将这些值存储在数组中,然后将这些值中的每个值以2对的形式打印出来2如何打印存储在数组中的值
以下是我有:
#include <iostream>
#include <string>
using namespace std;
int main()
{
const int SIZE = 3;
int time[SIZE] = {};
string name[SIZE] = {};
for (int a = 0; a < 3; a++)
{
cout << "Enter runner name: ";
getline (cin, name[+1]);
cout << "Enter runner time: ";
cin >> time[+1];
cin.ignore();
}
for (int a = 0; a < 3; a++)
{
cout << name << " finished in " << time << "\n";
}
return 0;
}
,我想我的输出看起来像这样:
name1 finished in time1
name2 finished in time2
name3 finished in time3
目前,我的输出看起来是这样的:
0x22fdf0 finished in 0x22fe10
0x22fdf0 finished in 0x22fe10
0x22fdf0 finished in 0x22fe10
如何,我可以得到的输入被存储在阵列中,然后输出这些值的用户?
如果这已经被回答了,道歉。我一直无法找到一个例子,其中数组填充了用户输入值,然后返回到显示器。
'函数getline(CIN,名称[1]);' - 请说出什么,这是该怎么办?什么是'name [+1]'?看起来你正在猜测要写什么,而不是看看一本好的C++书籍,以了解如何使用循环读入数组。 – PaulMcKenzie