I am wondering what syntax to use in order to count how many characters there are in my .txt file. In my .txt file is the alphabet (ABCDEFGHIJKLMNOPQRSTUVWXYZ), and that is all.
Here is what I have so far:
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
I suppose that you mean alpha characters. Otherwise you can use member function size() to determine how many characters the string contains. If so than you should use isalpha function. For example
1 2
int count = std::count_if( letters.begin(), letters.end(),
[] ( char c ) { return ( std::isalpha( c ) ); } );
It seems that your compiler does not support the new C++ Standard that is lambda expressions.
You can change the lambda expression to a functional object.
unless you're being excessively pedantic and coding for the imaginary standards-compliant implementation where <cctype>'s std::isalpha takes defaulted arguments past the int.
Also, the above samples count the letters per line. To count the entire file, iterate over the entire file: