Loading

C++里的getcahr()

https://www.dotcpp.com/oj/problem1094.html
getchar()在这里用来捕获回车,先输入n的值,然后敲回车,缓冲区会有一个回车,getline()会读入,用getchar()读入回车,清空缓冲区。

#include<iostream>
#include<string>
#include<cstdio>
using namespace std;
int main(void)
{
	string x;
	int n;
	cin >> n;
	getchar();
	for (int i = 0; i < n; i++)
	{
		getline(cin, x);
		cout << x << endl << endl;
	}
	while (cin >> x)
	{
		cout << x << endl << endl;
	}
	return 0;
}
posted @ 2021-01-10 22:15  longwind7  阅读(109)  评论(0)    收藏  举报