简体   繁体   中英

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM