Simple question - getline()

This is a discussion on Simple question - getline() within the C++ Programming forums, part of the General Programming Boards category; Hey, I have a simple question. My test main: Code: int main() { Player player; string name; cout << "Enter ...

  1. #1
    Registered User
    Join Date
    Jan 2006
    Posts
    20

    Simple question - getline()

    Hey, I have a simple question.

    My test main:
    Code:
    int main()
    {
    	Player player;
    
    	string name;
    
    	cout << "Enter your name: ";
    	getline(cin, name);
    
    	player.setName(name);
    	cout << player.getName() << endl;
    
    	return 0;
    }
    Everything works, but, when I fill the name in, getline ask for an extra <ENTER>. So when I input "Testname" followed by an enter, it displays a blank line and waits for an <ENTER> again. How can I make sure that it doesn't ask for that <ENTER> ?

  2. #2
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,006
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  3. #3
    ZuK
    ZuK is offline
    Registered User
    Join Date
    Aug 2005
    Location
    Austria
    Posts
    1,990
    Are you using VC6 ?
    http://www.dinkumware.com/vc_fixes.html
    Kurt

  4. #4
    Registered User
    Join Date
    Jan 2006
    Posts
    20
    OK thanks!

    I'm using Microsoft Visual C++ Enterprise edition, yes
    Last edited by QuietWhistler; 01-24-2006 at 12:18 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Simple class question
    By 99atlantic in forum C++ Programming
    Replies: 6
    Last Post: 04-20-2005, 11:41 PM
  2. Simple question about pausing program
    By Noid in forum C Programming
    Replies: 14
    Last Post: 04-02-2005, 08:46 AM
  3. simple question.
    By InvariantLoop in forum Windows Programming
    Replies: 4
    Last Post: 01-31-2005, 11:15 AM
  4. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 03:00 PM
  5. simple fgets question
    By theweirdo in forum C Programming
    Replies: 7
    Last Post: 01-27-2002, 05:58 PM

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