October 23, 2014 · Public
I'm trying to do s Word count, and a Character count from reading the file ONCE.
My solution was to load the ifstream TWICE (Not what I wanted !!)
Any suggestions, greatly appreciated.
#include // Pre-processor directive
#include // Used for string manipulation
#include // Required to manipulate a file stream
#include // Required for sleep command
using namespace std;
// This Program will Read a txt file, character by character
// and display it on the screen, as though it were being typed by someone
// And tell you how many characters are in the file
int main() // Title of our function (main)
int charCount=0; // This will hold our total character count
string words; // This is for reading the file as a string
char chars; // This is for reading the file Character by character
ifstream theFile("Test.txt"); // To read the Data from the file document named "XX.txt"
// Into variable 'theFile'
// Now the While loop, LOOPS through each piece of information and loads it to the appropriate variable
// Those variables are checked by the FILE PIOINTER
// File Pointer starts TOP LEFT of our txt file, it runs fro TOP LEFT to BOTTOM RIGHT through our file
while(theFile>>chars>>noskipws) // While this condition is TRUE the Loop continues
// The 'noskipws' Command, Causes C++ to 'Not Skip White Spaces'