#include<iostream>
#include<fstream>
#include"iomanip"
using namespace std;
bool isAlpha(char c);
void main()
{
ifstream ifile1("C:/a1.txt");
int i;
int rows = 0, words = 0;
bool inword = false;
char text[1000];
while (ifile1.peek()!=EOF)
{
i = 0;
ifile1.getline(text, 10000);
rows++;
while (text[i] != 0)
{
if (!isAlpha(text[i]))
{
inword = false;
}
else if (isAlpha(text[i]) && (!inword))
{
words++;
inword = true;
}
i++;
}
cout << i << ": " << setiosflags(ios::left) << text << endl;
}
cout << "rows:" << rows << endl;
cout << "words" << words << endl;
ifile1.close();
}
bool isAlpha(char c)
{
if ((c >= 'a'&&c <= 'z') || (c >= 'A'&&c <= 'Z'))
return true;
else
return false;
}
运行结果: