Thread: full name, one string

  1. #1

    Question full name, one string


    I'd like to be able to input a first and last name using one string.
    Is there a way to check for a space to know where to separate the first from last name?
    See, I dont' want to use two strings. One for first, and one for last.
    (This program isn't for any extremely useful purpose, I am still learning.)

    void enterName(void) {
    char name[50];

    cout << "Please Enter Your First and Last Name\n";
    cin >> name;

    /* find space in name */

    cout << "Welcome, " << name;


  2. #2
    use cin.getline(....) //cant remember the arguments

  3. #3
    Registered User
    Join Date
    Feb 2002

    using string

    its cin.getline( char *buffer, int length, char delimit = '\n')

    well not exactly with those variable names but you should get the picture....

    anyway also use the string class and you can do all kinds of mainpulation to the string....including checking for a space...


    using std::string;

    or something like that ....
    --true programmer's don't comment--
    --programmer wannabes complain about it--

  4. #4
    Registered User Paro's Avatar
    Join Date
    Feb 2002
    i dont know about everyone else but heres what i always do for that...

    #include "apstring.h"
    #include <iostream.h>

    int main()
    apstring name;

    cout<<"Enter your full name and press enter: ";
    getline (cin, name);

    cout<<"Hello, "<<name<<endl;

    return 0;
    i just pulled that out of thin air so it might have errors (doubt it) but if you have the apstring.cpp and apstring.h, open apstring.cpp and add it to your project, and make sure in the "TOOLS", then "options" section, in the "Directories" tab, you have a directory listed to your apstring files...

    hope that made SOME sense

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. We Got _DEBUG Errors
    By Tonto in forum Windows Programming
    Replies: 5
    Last Post: 12-22-2006, 05:45 PM
  3. Classes inheretance problem...
    By NANO in forum C++ Programming
    Replies: 12
    Last Post: 12-09-2002, 03:23 PM
  4. creating class, and linking files
    By JCK in forum C++ Programming
    Replies: 12
    Last Post: 12-08-2002, 02:45 PM
  5. Warnings, warnings, warnings?
    By spentdome in forum C Programming
    Replies: 25
    Last Post: 05-27-2002, 06:49 PM