这个程序怎么for循环后的不显示呢

来源:百度知道 编辑:UC知道 时间:2024/05/18 05:56:01
#include <iostream>
#include "string.h"
using namespace std;
int main()
{
int aCnt = 0,eCnt=0,iCnt=0,oCnt=0,uCnt=0,
theCnt=0,itCnt=0,wdCnt=0,notVowel=0;
string buf,the("The"),it("It");
while(cin >> buf){
++wdCnt;
cout << buf <<' ';
if(wdCnt%12==0)
cout << endl;
if(buf==the||buf=="The")
++theCnt;
else if(buf==it||buf=="It")
++itCnt;
for(int ix=0;ix<buf.size();++ix)
{
switch(buf[ix])
{
case 'a':case'A':++aCnt;break;
case'e':case'E':++eCnt;break;
case'i':ca

//程序大体上是对的,其中有一些不大影响结果的问题给你改了。
//你问的问题在于,这个程序用cin >> buf的返回值来判断读入
//单词的结束,所以必须等程序读不到单词时它才会输出for循环
//后面的统计结果。你大概直接用键盘输入调试,这样程序自然
//会一直等待输入,不会结束。
//因此程序不是写法的问题,而是用法的问题。解决的方法是输入
//句子时用Ctrl + Z(在Windows系统下会被解释为文件结束符)
//结束,或者把编译好的程序在命令行下用流的重定向功能直接把
//输入定向到磁盘文件,就可以了。

#include <iostream>
#include <string>
//因为用的是string类而不是C语言的串操作函数,所以头文件是string,不是string.h

using namespace std;
int main()
{
int aCnt = 0,eCnt=0,iCnt=0,oCnt=0,uCnt=0,
theCnt=0,itCnt=0,wdCnt=0,notVowel=0;
string buf,the("The"),it("It");
while(cin >> buf){
++wdCnt;
cout << buf <<' ';
if(wdCnt%12==0)
cout << endl;
if(buf==the) //一个判断就够了,下同
++theCnt;
else if(buf==it)
++itCnt;
for(int ix=0;ix<buf.size();++ix)