我是C ++的新手,这并不是我专业的真正组成部分,因此我有点迷茫!如果我可以亲自联系任何人寻求帮助,请告诉我:)我的程序将需要从文件中读取十个整数值,并将它们存储在数组或向量中。值的读取应在一个单独的函数中完成,该函数将整数数组作为参数,并从名为tempInput.txt的文件中读取。我不确定如何创建一个整数数组作为参数。然后,从main调用另一个函数,其签名和返回类型为:
bool isDangerous(int tempArray[ ]);
如果您可以在第一到第二部分中为我提供帮助,那就太好了!
namespace std;
int divison(int,int);
int main()
{
void readData(int tempArray[ ]);
int tempInput[10];
readData(tempInput);
//int size=10; //Array size
int sum =0;
//for(int i=0;i<size;i++) //Loop which inputs arrays data and
// {
//cout << myArray[i] << endl;
// }
return 0;
}
尽我所能理解的问题,这里有一些代码可以帮助您入门(请注意,我并没有完全填写所有内容,我不想为您完成工作)
#include<fstream> //So we can read from files
#include<iostream>
using namespace std;
void readData(int tempArray []) {
//Open file and read data into temp array
//If you need help reading data, see:
//http://www.cplusplus.com/doc/tutorial/files/
}
bool isDangerous(int tempArray []) {
//Do things
}
int main() {
int tempInput [10];
readData(tempInput); //Read the data into tempInput
bool result;
result = isDangerous(tempInput); //Do something with isDangerous
return 0;
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句