У меня проблемы с получением # из inData.txt и выводом значения в outData.txt
Значения, которые находятся в моем inData.txt:
10.20 5.35
Значения, которые появляются в моем 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 AssociationinFile >> 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;
}
Это проверит ваш код:
#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");
if(inFile.fail())
{
cerr << "Error opening inData.txt" << std::endl;
return -1;
}
if(outFile.fail())
{
cerr << "Error opening outData.txt" << std::endl;
return -1;
}
// Data Manipulation
outFile << fixed << showpoint;
outFile << setprecision(2);
cout << "Processing Data..." << endl;
// Variable Association
if(!(inFile >> length >> width)
{
cerr << "Failed to read values." << std::endl;
return -1;
}
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;
}
Других решений пока нет …