![]() |
|
#1
|
|||
|
|||
a quick questionhello friends, it's been a long time.
i had a quick question about the "getline" function. i was wondering if there was a way to use that function without including the number of characters to be taken in since that will vary. ???? |
|
#2
|
||||
|
||||
Re: a quick questionNo. And why would you? If you did, all you'd do is cause grief because you would have converted the safe getline() into the dangerous gets() (see this link).
And welcome back! __________________
Got a cough? Go home tonight and eat a whole box of Ex-Lax. Tomorrow, you'll be afraid to cough. -- Pearl Williams |
|
#3
|
|||
|
|||
Re: a quick questionQuote:
The second arbument is the maximum number of chars that you want getline to store (including the terminating zero byte). If the user hits "[Enter]" getline returns at that point: You would use it something like this: CPP / C++ / C Code:
Here's a sample run: Code:
Regards, Dave |
|
#4
|
|||
|
|||
Re: a quick questionthanks for the reply guys.actualy, the code is to read strings from a file.these strings a seperated by a period.the strings being read is not include the period so i have to set the period to be my delimeter in getline.the size of those strings vary ofcourse and that's where my problem come in.
|
|
#5
|
|||
|
|||
Re: a quick questionQuote:
Are you reading std::strings with the getline() function? There is no parameter for string size (std::string sizes take care of themselves --- that's one of the big (really big) advantages of std::strings compared to arrays of char). The way you worded the question, I thought you were referring to the istream::getline() member function, which reads into an array of char, and it has a parameter that tells what the maximum number of chars that you will allow. In general, if you have a question, here are some suggested steps: Write a program that reads whatever you want, using whatever function you want. If it doesn't work the way you had in mind, then 1. Show us the code. 2. Tell us what you gave the program as an input. 3. Tell us what you got as an output. 4. Tell us what you expected as an output. 5. Tell us what you didn't understand about the difference between (3) and (4). If your program won't compile, and you don't understand why, then 1. Show the code. 2. Show the compiler messages (Exact messages including line numbers). 3. Tell us what you don't understand about the messages. 4. Tell us what compiler/operating system you are using. Sometimes it makes a difference to someone who is trying to help. Regards, Dave |
|
#6
|
|||
|
|||
Re: a quick questionQuote:
__________________
Please read http://www.gidforums.com/t-5566.html. They were written to help you create a request that is readable and has enough information we can actually tell what you need help with. |
Recent GIDBlog
Stupid Management Policies by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Quick, Insertion, and Partition | silicon | C++ Forum | 0 | 18-May-2005 21:49 |
| Merge and Heap...which is really faster | silicon | C++ Forum | 0 | 10-May-2005 14:46 |
| non-member function question | crq | C++ Forum | 1 | 03-Feb-2005 22:59 |
| Simple question on arrays--please help! | brookeville | C++ Forum | 16 | 18-Nov-2004 00:23 |
| Repetition structure problem and question | brookeville | C++ Forum | 17 | 29-Oct-2004 18:48 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The