#include <fstream>
#include <cctype>

using namespace std;

size_t nLines = 0;
size_t nWords = 0;
size_t nChars = 0;

char prev=' ';

size_t CountCommas(istream & f)
{
size_t count = 0;
do {

if(f.peek()=='\n') nLines++;

if( (isspace(f.peek()) || f.eof()) && isalpha(prev))
{
nWords++;
}

prev = f.get();


}
while(f.good());
return count;
}

int main()
{
fstream f("sampleEng.txt");

if(!f.good())
{
cerr << "Error opening file" << endl;
return -1;
}

cout << "Lines = " << nLines << ",Words =" << nWords << ",Characters=" << nChars << endl;
return 0;
}

Последно модифициране: събота, 12 ноември 2011, 17:38