我想在函数中使用outf
,但是当我尝试显示'undefined'错误时。为什么我不能在函数中使用outf在C++中
我使用Visual Studio 2013,这是我的代码
int main(){
int costumer;
int d;
cout <<"Enter Number : ";
cin >> costumer;
d = costumer;
int *Erand = new int[d]; //Random Number 1
int *Srand = new int[d]; //Random Number 2
int *SumArrays = new int[d]; // sum Array
ofstream outf("Sample.dat");
//------------------------- Make Random Numbers
srand(time(0));
for (int i = 0; i< d; i++)
{
Erand[i] = 1 + rand() % 99;
}
for (int i = 0; i< d; i++)
{
Srand[i] = 1 + rand() % 999;
}
//---------------------------- Out Put
outf << "Random Number 1 " << endl;
for (int i = 0; i < d; i++) // i want it in a function
{
outf << Erand[i];
outf << ",";
}
outf << endl;
outf << "Random Number 2 " << endl;
for (int i = 0; i < d; i++)// i want it in a function
{
outf << Srand[i];
outf << ",";
}
outf << endl;
//--------------------------------calculator -------------------------
for (int i = 0; i < d; i++)
{
SumArrays[i] = Erand[i] + Srand[i];
}
outf << "Sum Of Array is : ";
outf << endl;
for (int i = 0; i < d; i++)
{
outf << SumArrays[i];
outf << ",";
}
outf << endl;
delete[] Erand;
delete[] Srand;
delete[] SumArrays;}
比如我想使用的功能随机数1:
void Eradom(){
for (int i = 0; i < d; i++)
{
outf << Erand[i];
outf << ",";
}
,但我行有错误4.
因此,这是第4行? –