Thread: [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
|
|
From: < =( > <vin...@ed...> - 2001-10-15 13:38:12
|
And like what I thought so, I was wrong... <IIIIIIIIIIIIIII> anyway, any of you guys know where I can get a C++ ebook? That is, the one I can download? the one that I have here was really meant as a tutorial - an introduction to the language, but it is not complete - I didn't even know the commands to flush the keyboard buffer! Well, hope you guys know where I can download a book... <IIIIIIIIIIIIIII> also, to julio, just to remind you, I was using the Cygnus Insight debugger(although not the current version). I prefer to use this than the console mode GNU debugger(because its easier to learn for me). if you downloaded dev-c++ from the internet, Insight is not included... you can download it from the resources page. If you already have it, well just try to use it... a debugger might be one of the tools that could help diagnose a problem(because it is a de-bugger). Well... I really hope that somehow I helped you... also, to all you folks! how do I use the "flush" function? what are its parameters? Thank you everyone in advance! __________________________________ www.edsamail.com |
|
From: Julio L. <ju2...@ya...> - 2001-10-15 21:32:40
|
I dont know how recent of an edition you are looking for, but there are some downloadable C++ books (like Sams Teach Yourself C++ in 21 Days 2nd Edition) here: http://www.informit.com/free_library/index.asp?st={FAA431F7-11F1-4FBF-8681-0C84321AEB69}&session_id={749C1C0D-7D5F-4319-B1DA-6392AB89175F} ____________ORIGINAL MESSAGE______________________ FROM: =DATE: 10/15/2001 06:47:04SUBJECT: [Dev-C++] RE: Re: RE: need help using cin.getline() And like what I thought so, I was wrong... <IIIIIIIIIIIIIII> anyway, any of you guys know where I can get a C++ ebook? That is, the one I can download? the one that I have here was really meant as a tutorial - an introduction to the language, but it is not complete - I didn't even know the commands to flush the keyboard buffer! Well, hope you guys know where I can download a book... <IIIIIIIIIIIIIII> also, to julio, just to remind you, I was using the Cygnus Insight debugger(although not the current version). I prefer to use this than the console mode GNU debugger(because its easier to learn for me). if you downloaded dev-c++ from the internet, Insight is not included... you can download it from the resources page. If you already have it, well just try to use it... a debugger might be one of the tools that could help diagnose a problem(because it is a de-bugger). Well... I really hope that somehow I helped you... also, to all you folks! how do I use the "flush" function? what are its parameters? Thank you everyone in advance! __________________________________ http://www.edsamail.com _______________________________________________ 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 |
|
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
|