[Dev-C++] RE: RE: RE: need help using cin.getline()
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Julio L. <ju2...@ya...> - 2001-10-14 18:43:50
|
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
|