Using strings with the copy constructor

This is a discussion on Using strings with the copy constructor within the C++ Programming forums, part of the General Programming Boards category; This should be a fairly easy question to answer, but it has me stumped. I need to be able to ...

  1. #1
    Unregistered
    Guest

    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
    Anti-Terrorist
    Join Date
    Aug 2001
    Location
    mming, Game DevelopmentCSR >&<>&2Minimization of boolean functions, PROM,PLA design >&0>&WA, USA guitar, dogsCommercial Aviation >&>>&USAProgramming
    Posts
    742
    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
    Posts
    4,831
    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...

    strcpy(string,o.string);
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  4. #4
    Unregistered
    Guest
    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, 04: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, 10:15 AM

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