好的,所以我试图返回正在从输入文件中读取值并显示在输出文件outFile上的坐标对。但是,什么都没有放在outFile流上。
现在忽略面积和距离值,我还没有解决这些问题
The distance between and is 6.9
The distance between and is 3.0
The distance between and is 6.9
The area of this triangle is: 10.1
使用cout时,值将显示在控制台中。void getPoint(ifstream &inFile, double x1, double y1){
ofstream outFile;
inFile >> x1 >> y1;
cout << fixed << setprecision(1) << "(" << round_off(x1,1) << "," << round_off(y1,1) <<")" << endl;
}
//Prints coordinates appropriately in console(1.0,1.2)
(6.0,6.0)
(6.0,6.0)
(3.0,6.5)
(1.0,1.2)
(3.0,6.5)
使用outFile时,坐标不会放在输出文件上,并且什么也不会返回。 (请参阅第一个图片)void getPoint(ifstream &inFile, double x1, double y1){
ofstream outFile;
inFile >> x1 >> y1;
outFile << fixed << setprecision(1) << "(" << round_off(x1,1) << "," << round_off(y1,1) <<")" << endl;
} //No values displayed in outFile
在不使用输出文件作为getPoint中的引用参数的情况下(如果它甚至可以解决它的idk问题),如何显示/返回getPoint()的坐标(x,y)到输出文件上?注意:
outFile << fixed << setprecision(1) << "(" << round_off(x1,1) << "," << round_off(y1,1) <<")" << endl;
可以在main函数中使用,但我希望它能相对于getPoint的参数起作用。上下文https://ctxt.io/2/AAAgYbZ5Ew的完整代码
最佳答案
报关单
ofstream outFile;
在函数main
和getPoint
中,阴影(隐藏)了全局ofstream outFile;
并防止其将内容打印到输出文件。如果由于某种原因而讨厌使用引用参数,则应删除它们以使函数使用全局outFile
。