Closed Thread
Results 1 to 4 of 4

Thread: Only first name

  1. #1
    Ronin is offline Programming Professional
    Join Date
    Apr 2006
    Posts
    309
    Rep Power
    24

    Only first name

    I use this:

    Code:
    string name;
    cin >> name;
    but when the user enters "Jane Doe" the name string only contains "Jane". How can I fix this?

  2. CODECALL Circuit advertisement
    Join Date
    Always
    Posts
    Many

     
  3. #2
    Join Date
    Jul 2006
    Posts
    16,486
    Blog Entries
    75
    Rep Power
    143
    try using cin.getline(name)
    Programming is a branch of mathematics.
    My CodeCall Blog | My Personal Blog

  4. #3
    icepack's Avatar
    icepack is offline Programmer
    Join Date
    Jul 2006
    Location
    North Carolina
    Posts
    115
    Rep Power
    21
    or use
    #include <string>


    and then, declare your string like

    string str1;

    cout << "Enter the name blah blah:\n";
    getline(cin, str1);

    should work fine
    Last edited by icepack; 11-12-2006 at 04:47 PM. Reason: find vs. fine

  5. #4
    Crane's Avatar
    Crane is offline Programming Expert
    Join Date
    Nov 2005
    Posts
    398
    Rep Power
    25
    The space is causing cin >> to terminate. Using the getline like suggested will read until a linebreak.

Closed Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts