constructor to set variable to an empry string

This is a discussion on constructor to set variable to an empry string within the C++ Programming forums, part of the General Programming Boards category; I am a new to c++, I have to set the variable name to an empty string in the class ...

  1. #1
    Registered User
    Join Date
    Feb 2002
    Posts
    20

    constructor to set variable to an empry string

    I am a new to c++, I have to set the variable name to an empty string in the class constructor. This is the way i approached it, is this correct?

    class test
    {
    private:
    char* name;

    prublic:
    Test()
    {
    name[0] = '\0';
    }

    };

  2. #2
    Registered User Dual-Catfish's Avatar
    Join Date
    Sep 2001
    Posts
    802

    Re: constructor to set variable to an empry string

    Originally posted by wireless
    I am a new to c++, I have to set the variable name to an empty string in the class constructor. This is the way i approached it, is this correct?

    class test
    {
    private:
    char* name;

    prublic:
    Test()
    {
    name[0] = '\0';
    }

    };

    First off, Test() should be test().


    test()
    {
    name = new char[input desired size];
    }

    Is what i'd use.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 8
    Last Post: 04-25-2008, 02:45 PM
  2. RicBot
    By John_ in forum C++ Programming
    Replies: 8
    Last Post: 06-13-2006, 06:52 PM
  3. Set string variable
    By Beaner in forum C Programming
    Replies: 3
    Last Post: 01-28-2006, 05:15 PM
  4. lvp string...
    By Magma in forum C++ Programming
    Replies: 4
    Last Post: 02-26-2003, 11:03 PM
  5. creating class, and linking files
    By JCK in forum C++ Programming
    Replies: 12
    Last Post: 12-08-2002, 01:45 PM

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