c++ 请高手指导一下,不胜感激!!!

来源:百度知道 编辑:UC知道 时间:2024/05/17 04:28:08
这个程序是完成一个元音字符个数的总数,我这个程序不对,不知道怎么调试,请高手帮个忙吧,给调试一下能运行了,谢谢啊!!
#include <string>
#include <iostream>
#include <fstream>
using namespace std;
void main()
{
string word;
int acnt=0,ecnt=0,icnt=0,ocnt=0,ucnt=0,wdcnt=0,non_vovlcnt=0;
int itcnt=0,thecnt=0;
int i=1;
ifstream infile("in_file.txt");
while(infile>>word)
{
cout<<"file read is:"<<word ;
if(word=="the"||word=="The") thecnt++;
if(word=="it"||word=="It") itcnt++;
for(int index=0;index<word.size();index++)
{
switch(word[i])
{
case'a':case'A':++acnt; break;
case'e':case'E':++ecnt; break;
case'i':case'I':++icnt; break

你的程序有许多问题,我就不一一指出了,不过要想编译通过很简单:

你的程序末尾少一个大括号,加上就可以:
#include <string>
#include <iostream>
#include <fstream>
using namespace std;
void main()
{
string word;
int acnt=0,ecnt=0,icnt=0,ocnt=0,ucnt=0,wdcnt=0,non_vovlcnt=0;
int itcnt=0,thecnt=0;
int i=1;
ifstream infile("in_file.txt");
while(infile>>word)
{
cout<<"file read is:"<<word ;
if(word=="the"||word=="The") thecnt++;
if(word=="it"||word=="It") itcnt++;
for(int index=0;index<word.size();index++)
{
switch(word[i])
{
case'a':case'A':++acnt; break;
case'e':case'E':++ecnt; break;
case'i':case'I':++icnt; break;
case'u':case'U':++ucnt; break;
default: ++non_vovlcnt;
}
cout<<i++;
}
}
}<