1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
|
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
struct Data
{
double m_X;
double m_Y;
double m_Z;
Data (){}
Data (const double X, const double Y, const double Z)
: m_X(X), m_Y(Y), m_Z(Z){}
Data (const Data& lhs, const Data& rhs)
: m_X(lhs.m_X + rhs.m_X), m_Y(lhs.m_Y + rhs.m_Y), m_Z(lhs.m_Z + rhs.m_Z){}
};
std::ostream& operator << (std::ostream& os, const Data& d)
{
os << std::setprecision(4) << std::setw(8) << std::left << d.m_X << std::setprecision(4) << std::setw(8)
<< std::left << d.m_Y << std::setprecision(4) << std::setw(8) << std::left << d.m_Z << "\n";
return os;
}
int main()
{
std::ifstream inFile {"D:\\input.txt"};
std::ofstream outFile {"D:\\output.txt"};
while(inFile)//to check file opening this can be put inside if(inFile) loop
{
std::string stringOne{};
getline(inFile, stringOne);
std::istringstream streamOne{stringOne};
double X_One{}, Y_One{}, Z_One{};
if(streamOne) streamOne >> X_One >> Y_One >> Z_One;
std::string dummy{};
getline(inFile, dummy);
std::string stringThree{};
getline(inFile, stringThree);
std::istringstream streamThree{stringThree};
double X_Three{}, Y_Three{}, Z_Three{};
if(streamThree) streamThree >> X_Three >> Y_Three >> Z_Three;
if(inFile)outFile << Data(Data(X_One, Y_One, Z_One), Data(X_Three, Y_Three, Z_Three));
}
}
|