Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Sep 25th, 2005, 8:20 AM   #1
LOI Kratong
Professional Programmer
 
Join Date: May 2005
Location: Woo - Boot Sector!
Posts: 294
Rep Power: 4 LOI Kratong is on a distinguished road
getline() skipping. help?

hey guys, i have a console program into which i want to put a menu. I have a partly working menu, but it skips the getline part... heres the code:

if (op == 1)
       {
              bruteforce_input(); //<----- skips this part
      //other code...
       }

and then the function:
void bruteforce_input ()
{
     cout << "\n\n\n\n\t\t To begin Brute Forcing a ceasar shift,\n\t\t enter the cipher text:\n\n\t\t>";
     getline(cin,ciphertext);
     cout << "\t\t --------------------------------------\n\n\n";
     cls();
     cout << "\n\n\t\tStarting the brute force...\n\n\n";    
}
the getline() as i mentioned before skips when i try to run the program. Anyone know why?
__________________
www.heldtogether.co.uk
LOI Kratong is offline   Reply With Quote
Old Sep 25th, 2005, 8:36 AM   #2
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
Have you done previous input? You probably have a newline in the buffer that is satisfying the call. Put cin.sync () prior to the call. After the call, TEST CIN FOR FAILURE. That would be, "if (!cin.good ()) // Bad news ". Failing to to this is the hallmark of a newb or a schlock.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Old Sep 26th, 2005, 1:34 PM   #3
LOI Kratong
Professional Programmer
 
Join Date: May 2005
Location: Woo - Boot Sector!
Posts: 294
Rep Power: 4 LOI Kratong is on a distinguished road
Yeah i have previous input... thanks.

Right suppose you could call me a schlock...
__________________
www.heldtogether.co.uk
LOI Kratong is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 5:21 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC