How to count alphabetic characters in text file with C++

1 Answer

0 votes
#include <iostream>
#include <fstream>

using std::cout;
using std::endl;

int main()
{
	std::ifstream ifs("d:\\data.txt");

	int counter = 0;
	char ch;

	while (!ifs.eof()) {
		ifs >> ch;
		if (isalpha(ch) && !ifs.eof()) {
			counter++;
		}
	}

	ifs.close();

	cout << counter << endl;

	return 0;
}

/*
run:

16

*/

 



answered Jun 13, 2018 by avibootz

Related questions

1 answer 218 views
2 answers 234 views
1 answer 235 views
2 answers 187 views
1 answer 191 views
1 answer 178 views
178 views asked Jun 10, 2018 by avibootz
...