My code is:
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main()
{
string line;
int charCount, lineCount;
ifstream infile;
infile.open(«file.txt»);
charCount=0;
lineCount=0;
if (infile.is_open())
{
while( getline (infile, line))
{
lineCount++;
charCount += line.length();
}
}
cout<<«Number of characters: «<<charCount<<endl;
cout<<«Number of lines: «<<lineCount <<endl;
infile.close( );
return 0;
}
This program analyzes a file and returns the total of characters and the total of lines. I made this code with help from youtube videos and some other blogs. Here I used #masterytopic21 because I read information from a file.