【发布时间】:2017-10-22 19:30:46
【问题描述】:
int itrtn;
cout << "How many iterations? ";
cin >> itrtn;
double leftx, rightx,midx,midy;
cout << "Enter the endpoints of the interval containing the root: ";
cin >> leftx>>rightx;
cout<<"Enter the polynomial coefficients, ascending in degree: ";
string degree;
getline(cin,degree); // gets an entire line of input
istringstream fake_keyboard(degree); // use fake keyboard like cin
vector<double> coefficients;
double coeff;
while (fake_keyboard >> coeff) coefficients.push_back(coeff);
这是我的代码,但对于第三个问题,我无法使用 getline 进行 cin。编译器只是跳过这一步并将向量设置为默认值零
【问题讨论】:
-
fake_keyboard的目的是什么?也许你需要真正的键盘。 -
在您输入
rightx之后,您使用什么键将输入“传递”到您的程序?Enter键?导致将换行符添加到输入缓冲区的那个?现在想一想std::getline默认会寻找什么?