我对此很新颖。我曾尝试阅读其他人的错误,因为我找不到解决办法。当我取出流的位并切换fout为cout然后程序工作正常,但我似乎无法得到它输出到文件。我确实提前制作了这个文件。
次要的:
我想也以某种方式使用1个回路,用于x的范围应在5个步骤0至10在步长为1,10〜50(在SquareMachine功能)。主循环中1位循环的规则相同,0到15为1度递增,15到45为5度递增。我相信有一种技术,我根本没有看到结合我的循环或一个循环......洞..哈哈得到它?无论如何,主要需要输出文件的帮助。
谢谢你的任何意见/援助
错误(S):
week4.cpp: In function ‘void ShowProgramHeader()’:
week4.cpp:34: error: ‘fOut’ was not declared in this scope
week4.cpp: In function ‘int main()’:
week4.cpp:44: error: ‘struct std::ofstream’ has no member named ‘is’
week4.cpp: In function ‘int SquareMachine()’:
week4.cpp:92: error: ‘fOut’ was not declared in this scope
代码:
#include <cmath>
#include<stdlib.h>
#include <iostream>
#include t<ime.h>
#include<cstdlib>
#include<unistd.h>
#include<iomanip>
#include<fstream>
using namespace std;
//Global Variable(s)
long fact(long n);
// Prototype(s)
int SquareMachine();
// Program Header
void ShowProgramHeader()
{
fOut << "Name" << endl;
fOut << "Class and Date \n\n\n" << endl;
}
//Command Center
int main()
{
ofstream fOut("sTable.out", ios::out| ios::trunc);
if(fOut.is.open())
{
ShowProgramHeader();
SquareMachine();
fOut << "Value---Output\n"<<endl;
for(long t =0; t <=15; t++)
{
fOut << setw(10) << t;
fOut << setw(20) << fact(t) << endl;
}
for(long t =20; t <=45; t=t+5)
{
fOut << setw(10) << t;
fOut << setw(20) << fact(t) << endl;
fOut.close();
}
}
else
cout<<"Unable to Open the file: sTable.out";
exit(-1);
}
long fact(long n)
{
if(n ==0 || n==1)
return 1;
else if(n==2 || n <= 15)
return n * fact(n-1);
else if(n <=15 || n <=45)
return n * fact (n-5);
}
int SquareMachine()
{
double x = 10;
int n = 2;
double z;
fOut << "\nNumber Sqrt Exp Pow\n";
for (z=0; z<=x; ++z)
{
fOut << setw(10) << left << z << setprecision(2);
fOut << setw(10) << left << sqrt(z) << setprecision(3);
fOut << setw(10) << left << exp(z) << setprecision(10);
fOut << setw(10) << left << pow(z,n) << setprecision(4);
fOut << "\n" ;
}
for (z=15; z<=50; z= z+5)
{
fOut << setw(10) << left << z << setprecision(2);
fOut << setw(10) << left << sqrt(z) << setprecision(3);
fOut << setw(10) << left << exp(z) << setprecision(10);
fOut << setw(10) << left << pow(z,n) << setprecision(4);
fOut << "\n" ;
}
fOut << " \n End of Part 1\n"<< endl;
}
'fOut'是一个自动变量,由'main'函数作用域。它只要'main'一样长,但只能在'main'中看到。第二个错误是一个错字。你在错误的地方丢了一个'.'。 – user4581301
谢谢,我不知道...... dangit!我会尽力现在解决这些错误。 –
嗯,不确定如何解决这个问题。 –