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

cin problem with strings

Discussion in 'C++' started by gabuchia, Oct 7, 2009.

  1. gabuchia

    gabuchia New Member

    Joined:
    Oct 4, 2009
    Messages:
    11
    Likes Received:
    0
    Trophy Points:
    0
    Hey guys, when I type my code to getline(cin,name); it skips this line of the code

    Code:
       string name;
                  cout << "Please Key in your full name: " << endl;
    	      getline(cin, name);
    	      cout << endl;
    	      cout <<"Hello "; 
    The display on the console skips the part where I input the name. And yes, I have used the header file string
     
  2. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,012
    Likes Received:
    203
    Trophy Points:
    0
    Occupation:
    Senior Support Engineer
    Location:
    England
    Works fine for me in Visual Studio 2008; made a small change to confirm name contains the expected value:
    Code:
    	string name;
    	cout << "Please Key in your full name: " << endl;
    	getline(cin, name);
    	cout << endl;
    	cout <<"Hello "<<name<<endl;
    
    Output:
    Please Key in your full name:
    Fred

    Hello Fred
     
  3. gabuchia

    gabuchia New Member

    Joined:
    Oct 4, 2009
    Messages:
    11
    Likes Received:
    0
    Trophy Points:
    0
    Thanks for the help :D. But I have the code cout << name << endl; below that line. Not sure why it did not work. But I fixed it by asking the user to type in his first and last name seperately ;)
     

Share This Page