关于缓冲 关于^z的小小疑问
程序代码:
#include<iostream> #include<string> #include<cctype> using namespace std; int main() { string currWord,preWord; cout<<"Enter somewords:(Ctral+Z to end)"<<endl; while(cin>>currWord) { #ifndef NDEBUG cout<<currWord<<endl; #endif if(!isupper(currWord[0])) continue; if(currWord==preWord) break; else preWord=currWord; } if(currWord==preWord&&!currWord.empty()) cout<<"The is no repeated wor that has initial capital."<<endl; else cout<<"There is no repeated word that has initial capital."<<endl; return 0; }
为何这段程序输入MM MM^Z时会出现跟所设计的结果不一样?
且程序第一次读入MM后不会立即读入MM^Z而是等到下次输入NN ^Z时再一起读入上次的MM^Z,
也就是说输入NN^Z加回车后程序读入的是MM^ZNN,