请教一个C++程序中的几个问题!急!

来源:百度知道 编辑:UC知道 时间:2024/05/30 15:16:55
#include<iostream>
using namespace std;
int main()
{
cout<<"Please enter a string of words,ctrl+z to stop inputting:";
int count=0;
char ch;
while(cin>>ch)
switch(ch)
{
case'f':
cin.get(ch);
switch(ch){
case'f':case'l':case'i':
count+=1;
break;}}
cout<<"ff,fl and fi appear "<<count<<" times";
return 0;
}
1.要结束while(cin>>ch) 是按 ctrl+z ,这个结束是指结束循环吗?
2.为什么switch(ch)的时候能判断第一个输入的字母?
3.cin.get(ch); 这是什么意思?
谢谢!

1,ctrl+z是windows下强制终止输入流,以使 cin 失效。
2,switch(ch)能判断 ch 里的字母 ,至于是第几个,看你的程序是怎么写的
3,这是读取一个字符,包括空白符,存入变量 ch 中