All times are UTC




Post new topic Reply to topic  [ 3 posts ] 
  Print view

program error
Author Message
PostPosted: Sun Oct 19, 2008 11:38 am 
Offline
New Coder

Joined: Thu Sep 11, 2008 1:47 pm
Posts: 2
when i run this program it skips the getline. I can change it to a normal cin, but i'd rather have a getline.

Code:
#include <iostream>
#include <string>
using namespace std;

int main ()
{
    string naam;
    char ckeuze;
    int hp;
    int ehp;
   
    hp = 10;
    ehp = 8;
   
    cout << "Voordat we beginnen zou je me je naam willen vertellen? (j of n)" << endl;
    cin >> ckeuze;
    if (ckeuze == 'j' || ckeuze == 'J')
    {
               cout << "Vertel hem maar." << endl;
               getline (cin, naam); \\ this one skips
    } else
         {
              naam = "onbekende krijger";
         }
         cout << "Ik heet je welkom, " << naam << ", In de wereld van magie en heldhaftigheid: Terlon." << endl;
         
         system ("pause");
         return 0;
}           


Top
 Profile E-mail  
 

Re: program error
PostPosted: Sun Oct 19, 2008 3:41 pm 
Offline
New Coder

Joined: Wed Sep 10, 2008 8:38 am
Posts: 11
Should the line not read:

Code:
cin.getline(buffer, maxbufferlength);


For Reference:

http://www.cplusplus.com/reference/iostream/istream/getline.html


Top
 Profile E-mail  
 

Re: program error
PostPosted: Sun Nov 16, 2008 10:56 pm 
Offline
New Coder

Joined: Sat Sep 13, 2008 7:11 am
Posts: 4
Location: Umeå, Sweden
I'm guessing it's a buffering problem. Try adding an additional getline after the first and see if that works. The getline probably picks up the newline that ends the previous cin call.

_________________
"The highest reward for man's toil is not what he gets for it, but what he becomes by it."
- John Ruskin (1819 - 1900)


Top
 Profile E-mail  
 

Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron