Re: [Dev-C++] RE: RE: RE: need help using cin.getline()
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Jason H. <jas...@bt...> - 2001-10-14 21:56:51
|
Saying flush function is a bit missleading as the flush() function is for
the output stream. The function you want is ignore(), which will discard a
certain number of characters from the input stream i.e.
cin.ignore(2);
This will discard two characters. I'm not going in depth into this function,
and it can do a little more than what I have said. I recomend that you get
yourself a good C++ reference book to help you answer questions like this. I
use "C++: The Complete Reference (third edition)" by Herbert Schildt for
syntax and function finding, and Bjarne Stroustrup's "C++ Programming
Language (third edtion)" for programming style related stuff. Both are good
books, although if you are an absolute beginner to programming in general I
recomend you also have a look at a beginners book. Note that there may be
newer editions than the ones I have.
Jason.
----- Original Message -----
From: "Julio Lajara" <ju2...@ya...>
To: <dev...@li...>
Sent: Sunday, October 14, 2001 7:43 PM
Subject: [Dev-C++] RE: RE: RE: need help using cin.getline()
> Can anyone show me how to use the flush function? I
> know you are supposed to be able to call it directly,
> but when I do, the compiler says I passed to few
> parameters... What am I supposed to pass to the flush
> function???
>
> ORIGINAL MESSAGE:
>
> FROM: People == DissapointmentDATE: 10/14/2001
> 06:47:03SUBJECT: RE: [Dev-C++] RE: need help using
> cin.getline() whoa. do not use this. it is very poor
> style, inefficient and could lead to
> problems. if you have something in the keyboard
> buffer, just use a flush
> function before your next input.
>
>
> >From: "<dA-Vin-G>" <<EMAIL: PROTECTED>>
> >To: "Dev-C++ mailing list" <<EMAIL: PROTECTED>>
> >Subject: [Dev-C++] RE: need help using cin.getline()
> >Date: Sun, 14 Oct 2001 13:09:38 +0800
> >
> >I dont really know if this is right or not, I'm still
> learning C++ but I
> >think I can help at this problem of yours. I had
> experience in programming
> >other languages and I hope it helps...
> >
> >I actually debugged you code. It wasn't really the
> program's error but a
> >LOGICAL ERROR - that is, the syntax is right, the
> compiler says it is
> >right, but what it does is "wrong". Still with me?
> >
> >My solution, I added the following line(s) to your
> code. Fortunately it
> >worked. I hope this works...
> >
> >char AbsorbKey[2];
> >cin.getline(AbsorbKey, 50);
> >
> >I added them to the "void menu()" function. It now
> looks like this:
> >
> >void menu() {
> > Book *storedBooks= new Book [20];
> > unsigned short int counter=1;
> >
> > int exit=1;
> > while(exit) {
> > unsigned short int menuChoice;
> > cout < "\n\n ***Welcome to the Library of
> > E-Books***\n\n\n";
> > cout < " (1) View Sample Book Info\n";
> > cout < " (2) Store New Book Info\n";
> > cout < " (3) Search Book Info\n";
> > cout < " (4) Leave the Library\n\n\n";
> > cout < " Enter Choice #: ";
> > cin > menuChoice;
> >
> > // This is what I added =>
> >
> > char AbsorbKey[2];
> > cin.getline(AbsorbKey, 50);
> >
> > // :~
> >
> > switch(menuChoice) {
> >
> > //...
> >
> > }//end switch(menuChoice)
> >
> > delete [] storedBooks;
> >
> > }//end while loop
> >
> >}//end menu()
> >
> >Explanation:
> >I don't really know how or why it happened. I arrived
> at this solution
> >because when I was debugging it (without the lines I
> added), I noticed that
> >the first byte of bAuthor always changes to "/00" or
> simply a empty
> >character. And then, it would pass the cin.getline()
> and assumed that there
> >was already input from the user.
> >
> >A hunch - a character that cant be read by "cin >
> int" was passed to
> >"cin.getline(char[], int)". The function thought that
> it had already
> >recieved the input it needed.
> >
> >I dont think this is the right explanation. But I
> hope it works for you...
> >It worked for me
> >
> >
> >
> >__________________________________
> >www.edsamail.com
> >
> >_______________________________________________
> >Dev-cpp-users mailing list
> ><EMAIL: PROTECTED>
> >https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
>
>
> _________________________________________________________________
> Get your FREE download of MSN Explorer at
> http://explorer.msn.com/intl.asp
>
>
> _______________________________________________
> Dev-cpp-users mailing list
> <EMAIL: PROTECTED>
> https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
>
>
> =====
> Julio
>
> __________________________________________________
> Do You Yahoo!?
> Make a great connection at Yahoo! Personals.
> http://personals.yahoo.com
>
> _______________________________________________
> Dev-cpp-users mailing list
> Dev...@li...
> https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
|