8iv.cpp

来自「C/C++程序设计导论(第二版)》程序源文件」· C++ 代码 · 共 25 行

CPP
25
字号
// roottbl.cpp   Display a table of square roots for a list of
//	 input values from the disk file "a:values.dat"
#include <iostream.h>
#include <fstream.h>
#include <math.h>
const int PRECISION = 4;						// output precision
const int WIDTH1 = 10;						// width of values column
const int WIDTH2 = 15;						// width of root column

void main ()
{	float value, root;
	ifstream infile ("values.dat", ios::in);

	cout << "  value          square root" << endl;

	cout.precision(PRECISION);					// set precision
	while (infile >> value)					// loop through file values...
	{	root = sqrt (value);
		cout.width(WIDTH1);				// input values use these cols
		cout << value;
		cout.width(WIDTH2);				// roots use next WIDTH2 cols
		cout << root << endl;
	}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?