| | |
Char array and Getline question - really basic
Thread Solved
![]() |
•
•
Join Date: Apr 2008
Posts: 185
Reputation:
Solved Threads: 10
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.
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.
C++ Syntax (Toggle Plain Text)
string myString; getline(cin, myString);
Chris
Knowledge is power -- But experience is everything
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.
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.
"We Americans got so tired of being thought of as dumb by the rest of the world that we went to the polls last November and removed all doubt."
~~~~~~~~~~~~~~~~~~
Looking for an exciting graduate degree? Robotics and Intelligent Autonomous Systems (RIAS) at SDSM&T See the program brochure here.
~~~~~~~~~~~~~~~~~~
Looking for an exciting graduate degree? Robotics and Intelligent Autonomous Systems (RIAS) at SDSM&T See the program brochure here.
![]() |
Other Threads in the C++ Forum
- Previous Thread: Using string as char array
- Next Thread: Comparisons
| Thread Tools | Search this Thread |
api array based binary bitmap business c++ c/c++ char class classes code coding commentinghelp compile console conversion count decide delete deploy desktop developer directshow dll download dynamic dynamiccharacterarray email encryption error faq file forms free fstream function functions game givemetehcodez graph guess gui hash homeworkhelp homeworkhelper iamthwee ifpug ifstream incrementoperators infinite input int integer java lib linkedlist linker listing loop looping loops map math matrix memory multiple news node output parameter pointer problem proficiency program programming project python random read recursion reference rpg string strings temperature template test text text-file tree url variable vector video win32 windows winsock wordfrequency wxwidgets






