Thread: string varibles??

  1. #1
    neopyhte Labmouse's Avatar
    Join Date
    Aug 2007
    Location
    Ireland
    Posts
    26

    string varibles??

    stupid question I know(only just starting out in c++)but how do you read in a sentence and print it out.Im using the string varible but can only ever print out the first word and not the second.I think it might have something to do with the spaces between the words?Any help much appreciated,

    Labmouse

  2. #2
    Registered User
    Join Date
    Feb 2006
    Posts
    312
    Quote Originally Posted by Labmouse View Post
    stupid question I know(only just starting out in c++)but how do you read in a sentence and print it out.Im using the string varible but can only ever print out the first word and not the second.I think it might have something to do with the spaces between the words?Any help much appreciated,

    Labmouse
    use the getline function. eg,
    Code:
    #include <iostream>
    #include <string>
    
    using namespace std;
    
    int main()
    {
        string full_name;
        cout << "Enter your full name: ";
        getline( cin, full_name );
        cout << "Hello " << full_name << endl;
    }

  3. #3
    neopyhte Labmouse's Avatar
    Join Date
    Aug 2007
    Location
    Ireland
    Posts
    26
    Thanks Bench,was working out of a book but lost it(dont ask!)and couldnt find the command on the internet,

    Labmouse

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C++ ini file reader problems
    By guitarist809 in forum C++ Programming
    Replies: 7
    Last Post: 09-04-2008, 06:02 AM
  2. Replies: 8
    Last Post: 04-25-2008, 02:45 PM
  3. Message class ** Need help befor 12am tonight**
    By TransformedBG in forum C++ Programming
    Replies: 1
    Last Post: 11-29-2006, 11:03 PM
  4. Classes inheretance problem...
    By NANO in forum C++ Programming
    Replies: 12
    Last Post: 12-09-2002, 03:23 PM
  5. Warnings, warnings, warnings?
    By spentdome in forum C Programming
    Replies: 25
    Last Post: 05-27-2002, 06:49 PM