简体   繁体   English

我不知道为什么我的文件没有写出来

[英]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.

相关问题 我无法弄清楚为什么此代码不起作用 - I cannot figure out why this code will not work 写一个分数类,我无法弄清楚这些错误 - Writing a fraction class and I cannot figure out these errors 我的最后一个正则表达式不起作用,但是我无法弄清楚为什么 - My last regular expression won't work but i cannot figure out the reason why 我的程序可以编译并运行,但不执行switch语句中的6个选项中的任何一个,而且我无法弄清楚为什么 - My program compiles and runs but does not do any of the 6 options in the switch statements and I cannot figure out why 我似乎无法弄清楚为什么我对文件的读/写功能不起作用 - I can't seem to figure out why my read/write to a file functions are not working 无法弄清楚为什么这个函数返回零 - Cannot figure out why this function returns zero 无法解析的外部符号,无法找出原因 - Unresolved external symbol, cannot figure out why 细分错误已解决,但无法找出原因 - The segmentation fault is resolved, but cannot figure out why 我无法找出带有向量或数组的指针 - I cannot figure out the pointers with vector or a array 无法弄清楚为什么我的反向功能变得糟糕 - Can't figure out why I am getting bad out put from my reverse function
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM