Results 1 to 3 of 3

Thread: Multiple words in a string variable

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Mar 2009
    Posts
    18

    Question Multiple words in a string variable

    Hello,

    I am pretty new to C++. I have a problem when using the console to enter multiple words into a string variable i.e. add='123 cplusplus street'.

    when I try to get a user to enter their address using cin it only captures the users 1st word entered i.e '123' rather then 123 cplusplus street.

    the code i'm using is:

    HTML Code:
    string test;
    
    cout << "Enter address: ";
    cin >> test;
    cin

    Thanks in advance

  2. #2
    PowerPoster kfcSmitty's Avatar
    Join Date
    May 2005
    Posts
    2,248

    Re: Multiple words in a string variable

    You want to use getline.

    Code:
    getline(cin, variable);
    cout << variable;

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Mar 2009
    Posts
    18

    Re: Multiple words in a string variable

    Thanks!!!

Posting Permissions

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



Click Here to Expand Forum to Full Width