Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a program that takes in a filename as a command line argument, opens the file and reads in its contents, and prints out the

Write a program that takes in a filename as a command line argument, opens the file and reads in its contents, and prints out the total number of non-whitespace characters to the screen.
image text in transcribed
In this exercise, you are to use an input file stream to read in a text file and output the total number of non-whitespace characters in the file. You can do this by using the stream extraction operator (>>) to read each item in the file to a string variable, and then use the string.length) method to keep a running count of the total number of characters. Criteria Your program should run like this: $ more sampleFile.txt Hello. How are you? $g++ labProgram.cpp $./a.out sampleFile.txt 16

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

Discuss the four basic ways to accomplish work.

Answered: 1 week ago