cin.getline() needs input twice

This is a discussion on cin.getline() needs input twice within the C++ Programming forums, part of the General Programming Boards category; heres the code: Code: #include <iostream> #include <string> using namespace std; int main(void) { char line[20]; cin.getline(line, sizeof(line)); cout << ...

  1. #1
    Registered User
    Join Date
    Feb 2002
    Posts
    31

    cin.getline() needs input twice

    heres the code:

    Code:
    #include <iostream>
    #include <string>
    using namespace std;
    
    int main(void)
    {
       char line[20];
    
       cin.getline(line, sizeof(line));
    
       cout << line << endl;
    
       return 0;
    }
    when compiling with djgpp (gxx), cin.getline() requires i input the string twice. i dont have this problem with msvc.

    is this a compiler bug or am i missing something that msvc is letting me get away with?

    please dont eat me alive if this has been asked before. ive searched the board and most of the post pertained to issues concerning cin leaving a '\n' in the input buffer and getline catching it.

    thanks

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,821
    Mmm, no idea

    I also compiled it with DJGPP(gxx) and it works just as you would expect.

    What do you get with
    D:\code>gxx --version
    3.03

  3. #3
    Registered User
    Join Date
    Feb 2002
    Posts
    31
    thanks for the reply.

    gxx --version gives me gcc.exe (GCC) 3.1.

  4. #4
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. I would love some input on my BST tree.
    By StevenGarcia in forum C++ Programming
    Replies: 4
    Last Post: 01-15-2007, 01:22 AM
  2. About aes
    By gumit in forum C Programming
    Replies: 13
    Last Post: 10-24-2006, 04:42 PM
  3. Structure and Linked List User Input Question
    By kevndale79 in forum C Programming
    Replies: 16
    Last Post: 10-05-2006, 12:09 PM
  4. Need help with structures
    By yoursport in forum C++ Programming
    Replies: 8
    Last Post: 04-20-2005, 12:59 PM
  5. cin.getline()
    By Ifurita. in forum C++ Programming
    Replies: 4
    Last Post: 05-29-2003, 02:14 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21