[英]I cannot figure out why my file is not writing out
#include<iostream>
#include<fstream>
using namespace std;
int main()
{
ifstream initialCost;
ofstream output;
output.open("output.txt");
initialCost.open("InitialCost.txt");
float csh1, af1, tr1, csh2, af2, tr2,tcsh1, tcsh2;
initialCost >> csh1 >> af1 >> tr1 >> csh2 >> af2 >> tr2;
tcsh1 =csh1+ (5*(csh1*tr1))+(5*af1);
tcsh2 =csh2+ (5*(csh2*tr2))+(5*af2);
cout<< "Initial House cost"<< '\t'
<< "Annual Fuel Cost" << '\t'
<< "Tax Rate" << '\t'
<< "Total Cost"<< '\n'
<< csh1 << '\t' << af1<< '\t' << tr1 << '\t' << tcsh1 << '\n'
<< csh2 << '\t' << af2<< '\t' << tr2 << '\t' << tcsh2 << '\n';
return 0;
}
My outputs are weird and I can't figure out why my second set of outputs are not working like the first. 我的输出很奇怪,我无法弄清楚为什么我的第二组输出不能像第一组输出那样工作。 Also I need my outputs to write into the output file.
另外,我需要将输出写入输出文件。
Change 更改
cout<< "Initial House cost"<< '\t'
to 至
output<< "Initial House cost"<< '\t'
I don't you meant to have commas in this line: 我不是要在这行中加上逗号:
initialCost >> csh1 >> af1 >> tr1 >> csh2, af2, tr2;
And writing to a file is done just like writing to std::cout
, both are output streams and works the same. 写入文件就像写入
std::cout
,两者都是输出流,并且工作原理相同。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.