Thread: Using strings with the copy constructor

  1. #1

    Using strings with the copy constructor

    This should be a fairly easy question to answer, but it has me stumped. I need to be able to use the copy constructor to copy a string that's entered by the user. When I try to do this the normal way I've been using the copy constructor, like so:

    member = class.member

    I get an error telling me that I need to use an LValue. This works for every other data type except strings. Thanks in advance.

  2. #2
    Join Date
    Aug 2001
    mming, Game DevelopmentCSR >&<>&2Minimization of boolean functions, PROM,PLA design >&0>&WA, USA guitar, dogsCommercial Aviation >&>>&USAProgramming
    Show your class declaration. Also you are talking about char arrays?
    I compile code with:
    Visual Studio.NET beta2

  3. #3
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    If you are using normal strings, (i.e. null terminated strings), you need to use the strcpy() function to copy the contents of one string to another...

    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  4. #4
    That worked beautifully adrianxw, thank you. I'm surprised I didn't try that, I've been working with C for so long and C++ classes are so different that it never crossed my mind to try using string.h. Thanks again

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Copy constructor question
    By BigFish21 in forum C++ Programming
    Replies: 9
    Last Post: 05-04-2008, 12:18 PM
  2. Why not use an = Operator instead of a Copy Constructor?
    By thetinman in forum C++ Programming
    Replies: 48
    Last Post: 10-15-2007, 03:58 PM
  3. Copy constructor
    By dude543 in forum C++ Programming
    Replies: 26
    Last Post: 01-26-2006, 05:35 PM
  4. copy constructor
    By paperbox005 in forum C++ Programming
    Replies: 4
    Last Post: 08-20-2004, 01:43 PM
  5. Copy Constructor Help
    By Jubba in forum C++ Programming
    Replies: 2
    Last Post: 11-07-2001, 11:15 AM