Thread: Skipping input...

  1. #1
    Registered User
    Join Date
    Sep 2003

    Skipping input...

    Explain why this happens and what I can do, please:
    #include <iostream.h>
    void main()
    	int junk;
    	char strSkipped[10], strNext[10];
    	cout << "C++ is messed up!\n";
    	cin >> junk;
    	cout << "\nThis next getline will be skipped for me\n";
    	cout << "\nBut then this is able to be accessed.\n";
    	cin.getline(strNext, 9);

  2. #2
    Registered User
    Join Date
    Jul 2003
    I think the reason is when you
    cin >> junk;
    the end of line char '\n' is left in the istream buffer
    so the next line reads from the buffer and gets an end of line char
    so continues to the next statement

  3. #3
    Registered User
    Join Date
    Sep 2003
    How can I fix that??

  4. #4
    Registered User major_small's Avatar
    Join Date
    May 2003
    put "cin.ignore(1);" before the cin.getline it's skipping.
    Join is in our Unofficial Cprog IRC channel
    Channel: #Tech

    Team Cprog Folding@Home: Team #43476
    Download it Here
    Detailed Stats Here
    More Detailed Stats
    52 Members so far, are YOU a member?
    Current team score: 1223226 (ranked 374 of 45152)

    The CBoard team is doing better than 99.16% of the other teams
    Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374)

    Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Input class project (again)
    By Elysia in forum C++ Programming
    Replies: 41
    Last Post: 02-13-2009, 10:52 AM
  2. 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
  3. About aes
    By gumit in forum C Programming
    Replies: 13
    Last Post: 10-24-2006, 03:42 PM
  4. Structure and Linked List User Input Question
    By kevndale79 in forum C Programming
    Replies: 16
    Last Post: 10-05-2006, 11:09 AM
  5. need help with some input
    By blindleaf in forum C Programming
    Replies: 2
    Last Post: 03-16-2003, 01:50 PM