填充数组
我正在尝试用整数填充数组,但我不太确定如何实现它。 我正在编写一个程序,询问每个人拥有的煎饼数量,我想将每个数量存储到一个数组中。
#include <iostream>
using namespace std;
int main ()
{
//An array of people
for(int i = 0; i<10; i ++)
{
int amount;
cout<<"How many pancakes did person eat? \n";
cin >> amount ;
people[i] = amount;
}
}
I'm trying to populate an array with integers, but I'm not quite sure how to implement it.
I'm writing a program that ask for the amount of pancakes each person has and im wanting to store each amount into an array.
#include <iostream>
using namespace std;
int main ()
{
//An array of people
for(int i = 0; i<10; i ++)
{
int amount;
cout<<"How many pancakes did person eat? \n";
cin >> amount ;
people[i] = amount;
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果你用 C++ 编程,你应该使用 std::vector 而不是普通数组。代码可能如下所示:
If you program C++ you should use std::vector instead of normal arrays. The code might then look like this:
您可以动态创建整数数组,如下所示:
或者,也可以静态定义:
比较它们之间的差异: http://www.cplusplus.com/forum/beginner/12755/
You can dynamically create an integer array as follows:
Or, it can statically be defined:
To compare the difference between them: http://www.cplusplus.com/forum/beginner/12755/