我发现这里的编码有问题。我需要从文本文件中读取,然后写入对象。但是,我可能做不到。对象中的值似乎没有初始化。
void readPolynomial(string filename, polynomial& p)
{
//Read in the terms of the polynomial from the data file.
//Terms in the data file are arranged in descending order by the exponent.
//One term per line (coefficient followed by exponent), and there is no blank line.
term temp = term();
double c = 0;
int e = 0;
ifstream fin;
fin.open(filename);
while(!fin.eof())
{
fin >> c >> e;
temp = term(c, e);
p.addTerm(temp);
}
fin.close();
}
这是类术语的头文件。
默认构造函数:
term()
{
coef = 0;
exp = 0;
}
term::term(double c, int e)
{
c = coef;
e = exp;
}