Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Trying to write a program but am stumped. Im trying to generate a command line utility that will generate a series of stats about the contents of a target textfile. Stuff like Number of lines, number of words etc etc.
The Program will take either one (1) or two (2) command line arguments.
1. The first (required) argument is the path and name of the text file for which statistics will be collected.
I was thinking of a structure but am a little confused how they work, could someone give me some suggestions on how to attack this.

You are asking for C++ help but refering to C struct.
If you wanted to do this in C++ you would need to use classes and figure out a way to hold your data in a class.
Im not sure of the details of your project so I cant quite give you more detail or an example of what I mean, but I would look at using classes if I were you and not structs.

structs and classes are essentially the same. Only difference is structs default to public and classes to private...however generally classes are used for more complicated things.
I do not think that the use of a class here is necessarry...ur problem seems fairly simple.
Getting the number of lines would be easy, just utilize the EOF and getLine functions of fstream.
Number of words would be ez as well...simply count the number of spaces that have no space to their left (to account for double spaces after periods, colons)
and your done!

![]() |
Batch Help
|
About Borelli34
|

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |