是: 10.20 5.35outData.txt不输出正确的价值观
的出现在我的outData.txt值是: 矩形: 长度= -92559631349317830000000000000000000000000000000000000000000000.00,宽度= -92559631349317830000000000000000000000000000000000000000000000.00,面积= 8567285355521621000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.00,周长= -370238525397271320000000000000000000000000000000000000000000000.00
这里是我的代码(现在我只是工作,输出的长度,宽度,面积和周长)
#include <iostream>
#include <fstream>
#include <string>
#include <iomanip>
using namespace std;
int main()
{
// Filestream Variable declaration
ifstream inFile;
ofstream outFile;
// Variable Declaration
double length, width, areaOfRectangle, perimeter, radius, areaOfCircle, beginningBalance, interestRate, pi,
circumference, endingBalance;
string firstName, lastName;
int age;
char ch;
// Opening Filestream Variables
inFile.open("inData.txt");
outFile.open("outData.txt");
// Data Manipulation
outFile << fixed << showpoint;
outFile << setprecision(2);
cout << "Processing Data..." << endl;
// Variable Association
inFile >> length >> width;
outFile <<"Rectangle:" << endl;
areaOfRectangle = length * width;
perimeter = (length * 2) + (width * 2);
outFile <<"Length= " << length << ", Width= " << width << ", Area= " << areaOfRectangle << ", Perimeter= " << perimeter << endl;
// Closing Filestream Variables
inFile.close();
outFile.close();
return 0;
}
你永远不会检查你的输入为成功。你怎么能确定他们被正确地读了? – chris
对不起,我不明白。我究竟做错了什么? – Isaac
您可以在布尔上下文中检查'inFile >>长度>>宽度;'。如果没有阅读任何一个,这将是错误的。 – chris