Enter an article without giving the number of words. Use a cin loop to get each word. How to stop the loop at the end of the article?
For example:
Input: to be or not to be is a question
Code:
string a;
while( ? ) //無法停止循環(huán)
{
cin >> a;
// Do some thing...
}
while(cin >> a)
{
// Do some thing...
}
cin在讀取輸入流的末尾是會設(shè)置標(biāo)記位failbit為false