@C++使用回车键结束while(cin>>)循环输入
用到C++的get()函数,不用在键盘上敲击Ctrl+Z,输入结束直接回车即可结束输入
具体代码如下:
#include <iostream>
using namespace std;
int main(){
int b = 0;
char c;
while ((cin >> b).get(c))
{
cout << b << endl;
if (c =='\n')
break;
}
cout << "结束" << endl;
return 0;
}
运行结果