想知道c++输入数据个数未知情况下输入方法,并且什么时候停止
Windows系统终端下按Ctrl+Z再回车结束输入
Linux系统终端下按Ctrl+D结束输入
#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;
int main()
{
double x1, y1, x2, y2;
while (cin >> x1 >> y1 >> x2 >> y2)
{
double dx = x2 - x1;
double dy = y2 - y1;
double d = sqrt(dx * dx + dy * dy);
cout << fixed << setprecision(2) << d << '\n';
}
}