В этом коде fout является объектом ofstream, он предполагает запись в файл с именем output.txt
. По причине output.txt
всегда пусто! Я хотел бы спросить об ошибке, которую я сделал в коде:
#include<iostream>
#include<fstream>
#include<stdio.h>//to pause console screen
using namespace std;
double Volume(double);
int main() {
ifstream fin; //read object
ofstream fout;// writing object
double Radius;
fin.open("input.txt");
fout.open("output.txt");
if(!fin){
cout<<"There a problem, input.txt can not be reached"<<endl;
}
else{
fin>>Radius;
fout<<Volume(Radius);
cout<<"Done! check output.txt file to see the sphare volume"<<endl;
}
getchar();//to pause console screen
return 0;
}
double Volume(double r){
double vol;
vol= (4.0/3.0)*3.14*r*r*r;
return vol;
}