I have to make a program that reads in words, deletes certain ones, stores ones that pass, and then count the total. He didn't exactly specify how the words would be coming it, but I'm assuming that if a space at the end of the word is bad, that it's probably a word on each line. So, getline sounds like the best way to get the information.

Of course, these words he is giving us to store could be a web address for all we know. So, what would be a good size for me to initialize the array to, or is there a way to store it in a string so I wouldn't have to worry about the size.

8 Years
Discussion Span
Last Post by DemonGal711

It kind of depends on how the assignment defines "words". If you mean any sequence of displayable characters, bounded by whitespace (thus, a punctuation would be included with the word it precedes or follows), then cin >> would do the job of isolating individual words. If you have a more restrictive definition, such as just the sequence of alphabetic characters (no digits or punctuation) you will have to do a bit more more. You could still use the cin >>, then examine the beginning and ending character(s) of the word to determine more about its state. You might trim off punctuation.

cin >> has the benefit of not being concerned with number of words on an input line, it stops at each.

You could use a char array of any large size you want (256, 1024....) or you could use the string type.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.