Thread: Passing strings, please help!

  1. #1
    Registered User
    Join Date
    Dec 2001

    Unhappy Passing strings, please help!

    Hi thanks for looking...

    Below is the main method, followed by the student class. I want to pass the string (called name) onto the student class. What am I doing wrong?

    #include <iostream.h>
    #include <string.h>
    #include "student.h"

    void main(void)
    char name[10];
    cin.getline(name, 10, '\n');
    Person joe(name);

    cout<< name;
    cout<< joe.display();

    int i;
    cin >> i;

    //below is the "student.h" class
    class Person
    char name[10];
    Person(char nam[10])

    char display()
    return name;

  2. #2
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    In the Constructor, recieve "nam" as a reference. Also use Strcpy() to store it in "name", dont use '='.

    You might also want to pass the display as a pointer

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Passing Array of Strings to a function ??
    By Taper in forum C Programming
    Replies: 20
    Last Post: 12-07-2008, 02:58 PM
  2. Passing strings to functions and modifying them
    By diddy02 in forum C Programming
    Replies: 6
    Last Post: 08-11-2008, 01:07 AM
  3. passing strings from functions as the "return" part
    By fraktal in forum C Programming
    Replies: 8
    Last Post: 12-13-2005, 01:38 AM
  4. Passing an Array of Strings from VB to a C DLL
    By mr_nice! in forum Windows Programming
    Replies: 9
    Last Post: 03-08-2005, 06:16 AM
  5. Passing Strings by Reference
    By xshapirox in forum C++ Programming
    Replies: 3
    Last Post: 10-11-2004, 09:35 AM