用C++ 写游戏hangman出现了一些问题希望大家可以指点一下(文件读入后统计字符串个数出现问题)
#include<iostream>#include<ncurses.h>
#include<fstream>
#include<string>
using namespace std;
int main()
{
char a,h,b,d;
a='/';
h='o';
b='|';
d='-';
int row,col;
initscr();
char line[9][10]={
" _______",
" | |",
" | ",
" | ",
" | ",
"|_|______",
"| |",
"|_______|",};
int i,j,n=0;
for(i=0;i<=7;++i)
{
for(j=0;j<=8;++j)
{ mvprintw(5+i,3+j,"%c",line[i][j]);
}
}
refresh();
getch();
endwin();
string fileName = "dictionary";
ifstream infile(fileName.c_str());
if(infile.good()==false)
cout<<" can't open this dictionary."<<endl;
while(true) //这里我想用while循环得到dictionary 文件中的单词个数
{
n++;
if (infile.eof())//当读入到文件尾的时候跳出循环
break;
}
infile.close();
cout<<"there are "<<n<<"words in this dictionary"<<endl;
return 0;
}