【发布时间】:2015-04-02 16:16:07
【问题描述】:
我正在使用 Visual Studio 2013、c++、控制台应用程序。很长一段时间以来,我一直在为一个问题苦苦挣扎。我想知道是否有一种方法可以通过用户输入来初始化数组,例如:
我有一个数组:int arr[] = { 3, 7, 5, 9, 1};。因此,我希望初始化值是用户输入。
有什么办法可以做到吗?我们将不胜感激所有帮助和 cmets。
这是我的代码: cout > 元素;
cout << "Enter the difference value: ";
cin >> difference;
cout << "Enter the sequence of elements: ";
vector<int> arr(elements);
for (int i = 0; i < elements; i++)
{
cin >> arr[i];
}
//the following needs to have an array
//in their respective functions.
sorter(arr[], elements);
elementsDifference(arr[], elements, difference);
这个程序必须遍历一个数组并找到具有给定差异的对。
【问题讨论】:
标签: arrays c++11 visual-studio-2013 console-application