我有一份参考文件:
3 2
5 1
3 0
XXX
2 1
3 0
I need to read each integer separately, putting it into a polynomial. The "XXX" represents where the second polynomial will start. Based on the above example, the first polynomial will be 3x^2 + 5x^1 + 3x^0 and the second would be 2x^1 + 3x^0.
#include <iostream>
#include <iomanip>
#include <fstream>
#include "PolytermsP.h"
using namespace std;
int main()
{
// This will be an int
coefType coef;
// This will be an int
exponentType exponent;
// Polynomials
Poly a,b,remainder;
// After "XXX", I want this to be true
bool doneWithA = false;
// input/output files
ifstream input( "testfile1.txt" );
ofstream output( "output.txt" );
// Get the coefficient and exponent from the input file
input >> coef >> exponent;
// Make a term in polynomail a
a.setCoef( coef, exponent );
while( input )
{
if( input >> coef >> exponent )
{
if( doneWithA )
{
// We passed "XXX" so start putting terms into polynomial B instead of A
b.setCoef( exponent, coef );
} else {
// Put terms into polynomail A
a.setCoef( exponent, coef );
}
}
else
{
// Ran into "XXX"
doneWithA = true;
}
}
The problem I m having is that the values for polynomial A (what comes before XXX) are working, but not for B.
What I m asking is: How do I make it so when I run into "XXX" i can set "doneWithA" to true, and continue reading the file AFTER "XXX"?