Here is source code of the C++ program which counts the number of white-space characters in a file. The C++ program is successfully compiled and run on a Linux system. The program output is also shown below.
* C++ Program to Count the White-Spaced Characters in a File
int count = 0;
while (getline(file, line))
for (int i = 0; i < line.length(); i++)
if (line[i] == ' ' || line[i] == '\t')
std::cout << "Number of white-space characters"
<< " is " << count << "\n.";
$ g++ main.cpp $ ./a.out Number of white-space characters is 155.
Sanfoundry Global Education & Learning Series – 1000 C++ Programs.