Click to See Complete Forum and Search --> : Input string problems - urgent !!!


shilpichaudhry
December 10th, 2002, 05:40 PM
I have to ask the user to enter a value which he could leave empty if he wishes to.
If I use cin, it is required that he enter something at least
getch() - when he uses backspace, the character is not deleted
getline - requires him to press enter twice
scanf - requires him to enter something at least
gets - sometimes the program skips the code.

could somebody help me out with this,
Shilpi

jfaust
December 10th, 2002, 05:52 PM
getline - requires him to press enter twice


This is a bug with the library. Unfortunately, I'm not sure how to fix it. Maybe somebody else can enlighten us...

Jeff

PaulWendt
December 10th, 2002, 06:57 PM
If you're using Visual Studio 6.0 or less, check out this page,
which gives many bug fixes to "tide you over" until Visual
Studio .NET: http://www.dinkumware.com/vc_fixes.html

In particular:

The header <istream> contains a definition for member function basic_istream::getline. It has a lookahead problem -- typing a delimiter to end the input doesn't return control until you type yet another character. Change the code as indicated by the comment:


else if (_C == _Di)
{++_Chcount;
rdbuf()->snextc(); // replace snextc with sbumpc
break; }


Note that V6.0 replaces snextc with stossc. It is an adequate fix, but you can also apply the above patch safely.


--Paul

shilpichaudhry
December 10th, 2002, 08:11 PM
Why is it that sometimes, my program does not ask the user for input even if I have used gets();
Thanks, Shilpi