DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   C++ (http://www.daniweb.com/forums/forum8.html)
-   -   Char array and Getline question - really basic (http://www.daniweb.com/forums/thread160454.html)

DemonGal711 Dec 2nd, 2008 6:19 pm
Char array and Getline question - really basic
 
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.

Freaky_Chris Dec 2nd, 2008 6:31 pm
Re: Char array and Getline question - really basic
 
string myString;
getline(cin, myString);

Chris

vmanes Dec 2nd, 2008 6:51 pm
Re: Char array and Getline question - really basic
 
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.

DemonGal711 Dec 2nd, 2008 7:36 pm
Re: Char array and Getline question - really basic
 
Thanks. I forgot after that you can have it just output to a string...


All times are GMT -4. The time now is 12:11 pm.

Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC