Thread: little problem

  1. #1
    nugget_head
    Guest

    little problem

    Code:
    cout << "Please enter a name for your map:" << endl;
    cin.getline(mapName,sizeof(mapName),'\n');
    cout << "Enter the number of map rows:" << endl;
    cin.getline(rows,sizeof(rows),'\n');
    the output is:
    Please enter a name for your map:
    Enter the number of map rows:

    the first question is being skipped...what am i doing wrong? i've use cin.getline() before and never had a problem with it..


    thanks.

  2. #2
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    have you used cin>> before the getline anywhere?
    Chances are there are crap chars left in cins streambuf so clear them out with a cin.ignore(80,'\n'); before the first getline.
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

  3. #3
    Registered User
    Join Date
    Nov 2002
    Posts
    87
    I had this problem as well. Untill I bought myself a new book, I couldn't understand why the hel MSVC++ wasn't compiling it right. Because DEV-C++ automatically put this in for me.
    **********************
    *==================*
    * Many Can. One Must... *
    *==================*
    **********************

  4. #4
    Registered User
    Join Date
    Nov 2001
    Posts
    1,348
    Consider std::getline(cin, stringObject).

    Kuphryn

  5. #5
    bigwullie
    Guest
    This works with Borland compiler

    char rows[20];
    char mapName[10];

    cout << "Please enter a name for your map:" << endl;
    cin.getline(mapName,sizeof(mapName),'\n');
    cout << "Enter the number of map rows:" << endl;
    cin.getline(rows,sizeof(rows),'\n');

  6. #6
    nugget_head
    Guest
    thanks very much, everyone. stoned coder's suggestion worked perfectly. i did have a couple cin statements above these getline statements, and i thought that might be the problem. thanks again to all of you!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need help understanding a problem
    By dnguyen1022 in forum C++ Programming
    Replies: 2
    Last Post: 04-29-2009, 04:21 PM
  2. Memory problem with Borland C 3.1
    By AZ1699 in forum C Programming
    Replies: 16
    Last Post: 11-16-2007, 11:22 AM
  3. Someone having same problem with Code Block?
    By ofayto in forum C++ Programming
    Replies: 1
    Last Post: 07-12-2007, 08:38 AM
  4. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 02:51 PM
  5. WS_POPUP, continuation of old problem
    By blurrymadness in forum Windows Programming
    Replies: 1
    Last Post: 04-20-2007, 06:54 PM