這個是用來清空cin緩衝區裡面未讀取的資訊...
例子:
#include <iostream>
using namespace std;
int main () {
char first, second;
cout << "Please, enter a word: ";
first=cin.get();
cin.sync();
cout << "Please, enter another word: ";
second=cin.get();
cout << "The first word began by " << first << endl;
cout << "The second word began by " << second << endl;
return 0;
}
樣例輸入:
you
me
樣例輸出:
The first word began by y
The second word began by m
這個是用來清空cin緩衝區裡面未讀取的資訊...
例子:
#include <iostream>
using namespace std;
int main () {
char first, second;
cout << "Please, enter a word: ";
first=cin.get();
cin.sync();
cout << "Please, enter another word: ";
second=cin.get();
cout << "The first word began by " << first << endl;
cout << "The second word began by " << second << endl;
return 0;
}
樣例輸入:
you
me
樣例輸出:
The first word began by y
The second word began by m