full name, one string

This is a discussion on full name, one string within the C++ Programming forums, part of the General Programming Boards category; Hi. I'd like to be able to input a first and last name using one string. Is there a way ...

  1. #1
    Unregistered
    Guest

    Question full name, one string

    Hi.

    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.)
    eg.


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

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

    /* find space in name */

    cout << "Welcome, " << name;

    return;
    }

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

  3. #3
    Registered User
    Join Date
    Feb 2002
    Posts
    25

    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...

    include<string>

    using std::string;

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

  4. #4
    Registered User Paro's Avatar
    Join Date
    Feb 2002
    Posts
    160
    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
    Paro

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, 07: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, 07:49 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21