Thread: combining multiple strings into 1 string

  1. #1
    Unregistered Leeman_s's Avatar
    Join Date
    Oct 2001

    combining multiple strings into 1 string

    I'm having some trouble doing something like this:

    char first[10];
    char second[10];
    char third[10];
    char final[30];
    final = first + second + third;
    I get an error saying "cannot add two pointers", how would I do this?

  2. #2
    Join Date
    Aug 2001
    Groningen (NL)
    That is correct, first, second, third and final are pointers. You could use standard C functions for this. For adding strings you can use the function strcat(). Or you could try the C++ type string.

  3. #3
    I lurk
    Join Date
    Aug 2002
    As Shiro said:
    string first,second,third;
    // ...
    string final(first+second+third);

  4. #4
    Registered User Cela's Avatar
    Join Date
    Jan 2003
    Since this is C++ you should avoid using low level C strings whenever possible and play with the much better string class. That way you don't have to fool around with functions like strcmp and strcpy. :-)

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Separate long string into multiple arrays
    By cashmerelc in forum C Programming
    Replies: 6
    Last Post: 11-27-2007, 02:57 AM
  2. Help! Homework using Strings
    By wco5002 in forum C++ Programming
    Replies: 16
    Last Post: 09-27-2007, 03:53 AM
  3. We Got _DEBUG Errors
    By Tonto in forum Windows Programming
    Replies: 5
    Last Post: 12-22-2006, 05:45 PM
  4. Classes inheretance problem...
    By NANO in forum C++ Programming
    Replies: 12
    Last Post: 12-09-2002, 03:23 PM
  5. string handling
    By lessrain in forum C Programming
    Replies: 3
    Last Post: 04-24-2002, 07:36 PM