Write a user-defined function in C++ to read the content from a text file OUT.TXT, count and display the number of alphabets present in it.
#include<iostream>
#include<fstream>
#include<string>
using namespace std;
void countDisplay();
main()
{
countDisplay();
}
void countDisplay()
{
int count=0,ans=0;
ifstream myFile("Out.txt");
char a[40];
while(!myFile.eof())
{
myFile >> a;
count=strlen(a);
ans=ans+count;
cout << a<<endl;
}
cout<<"\nThere are total of "<<ans<<" Characters in this file\n\n";
system("pause");
}
No comments:
Post a Comment