1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

ask to cin.getline ()

Discussion in 'C++' started by meyup, Jun 15, 2010.

  1. meyup

    meyup New Member

    Joined:
    Feb 15, 2010
    Messages:
    102
    Likes Received:
    0
    Trophy Points:
    0
    Hello!

    I want to read a certain number of characters using cin stream of one. All I'll simply getline () works great for files but not when it is read from the keyboard.
    have therefore designed the following:
    Code:
    char s [50]; 
    court <<"Input:"; 
    cin.getline (s, 11, 'x'); 
    court <<endl <<"read ["<<s <<"]"<<endl;
    which should lead to I 10 via keyboard sign reading, until I either a 11th enter, or 'x' press.
    but actually I ALWAYS (even if limitter = 'x') the input end with ENTER. is it ok according to standard, or is this simply the compiler / OS, that it does not work without a final ENTER ...?
     
  2. inspiration

    inspiration New Member

    Joined:
    Feb 15, 2010
    Messages:
    85
    Likes Received:
    0
    Trophy Points:
    0
    For keyboard input expected C (+ +) almost always a Enter
     
  3. techme

    techme New Member

    Joined:
    Feb 15, 2010
    Messages:
    86
    Likes Received:
    0
    Trophy Points:
    0
    ... stupidly.

    but there is a standards compliant way that directly reads the entered without enter?
     
  4. inspiration

    inspiration New Member

    Joined:
    Feb 15, 2010
    Messages:
    85
    Likes Received:
    0
    Trophy Points:
    0
    No. Not on the keyboard.
     
  5. techinspiration

    techinspiration New Member

    Joined:
    Feb 14, 2010
    Messages:
    54
    Likes Received:
    0
    Trophy Points:
    0
    I have the problem that I need a command that waits for an Enter
    and still reads more than up to the space.
    If I

    cin> variable>>;

    work, he reads it only to the blanks.

    If I

    cin.getline (variable, 50);

    While working, he reads everything but no one waits for my input and I in a loop applying it to make program more easily and then reads the one thing I spend next.

    Can someone help me there?
     
  6. meyup

    meyup New Member

    Joined:
    Feb 15, 2010
    Messages:
    102
    Likes Received:
    0
    Trophy Points:
    0
    Hi,
    I do not understand your problem. Can you ever post some code that illustrates the sameness?
     
  7. techinspiration

    techinspiration New Member

    Joined:
    Feb 14, 2010
    Messages:
    54
    Likes Received:
    0
    Trophy Points:
    0
    This is my loop
    Code:
    do 
    ( 
    menue (); 
    court <<""; 
    cin>> e; 
    switch (e) 
    ( 
    case 1: 
    schl.text_eingabe () <- This is called input 
    break; 
    case 2: 
    schl.text_ausgabe (); 
    break; 
    case 3: 
    (Schl.text_speichern); 
    break; 
    case 4: 
    schl.verschl (); 
    break; 
    case 5: 
    schl.entschl (); 
    break; 
    ) 
    ) While (e! = 0); 
    
    This happens in the input function:

    court <<"Please enter the text: \ n";
    cin.getline (text, 49);

    Unfortunately, the command waits not now that what I type and the loop continues. With cin>> variable; goes just because it is not so read only up to the space
     
  8. meyup

    meyup New Member

    Joined:
    Feb 15, 2010
    Messages:
    102
    Likes Received:
    0
    Trophy Points:
    0
    Code:
    void clearIn () 
    ( 
        cin.clear (); 
    # If DAS_MIT_IGNORE_NICHT_FUNKTIONIERT 
        cin.sync (); 
    # Else 
        cin.ignore (cin.rdbuf () -> in_avail ()); 
    # Endif 
    ) 
    
    int main () 
    ( 
    ... 
    cin>> e; 
    (ClearIn)  / / ignore characters in the input buffer. 
    ... 
    )
     

Share This Page