本文整理汇总了C++中FileManager::savePoly方法的典型用法代码示例。如果您正苦于以下问题:C++ FileManager::savePoly方法的具体用法?C++ FileManager::savePoly怎么用?C++ FileManager::savePoly使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FileManager
的用法示例。
在下文中一共展示了FileManager::savePoly方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main(int argc, char** argv)
{
FileManager fManager;
char c;
bool read = false, save = false;
string fileToRead, fileToSave;
double startPoint = 1.0;
Polynomial *poly;
//parse program's arguments
while((c = getopt(argc, argv, "r:s:p:t")) != -1)
{
switch(c)
{
case 'r':
//read polynomial from specified file
read = true;
fileToRead = optarg;
break;
case 's':
//save polynomial to specified file
save = true;
fileToSave = optarg;
break;
case 'p':
//define starting point for Newton's method
startPoint = atof(optarg);
break;
case 't':
//run tests
testsRun();
return 0;
}
}
if(read)
{
//read specified file to load polynomial
poly = fManager.readPoly(fileToRead);
if(!poly)
{
cout << "Error while loading polynomial\n";
return 0;
}
cout << *poly << endl;
}
else
{
//get polynomial string from standard input
string polyString;
getline(cin, polyString);
//parse polynomial string
poly = fManager.polyGetFromString(polyString);
if(!poly)
{
cout << "Error while creating polynomial\n";
return 0;
}
}
//calculate root of polynomial using Newton's method
Root result = poly->calculateRoot(startPoint);
cout << "result: " << result.getX() << ", " << result.getY() << endl;
if(save)
{
//save polynomial to specified file
if(!fManager.savePoly(poly, fileToSave))
{
cout << "Failed to save polynomial\n";
}
}
}