combining multiple strings into 1 string

This is a discussion on combining multiple strings into 1 string within the C++ Programming forums, part of the General Programming Boards category; I'm having some trouble doing something like this: Code: char first[10]; char second[10]; char third[10]; char final[30]; final = first ...

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

    combining multiple strings into 1 string

    I'm having some trouble doing something like this:

    Code:
    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
    Location
    Groningen (NL)
    Posts
    2,386
    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
    Posts
    1,361
    As Shiro said:
    Code:
    string first,second,third;
    
    // ...
    
    string final(first+second+third);

  4. #4
    Registered User Cela's Avatar
    Join Date
    Jan 2003
    Posts
    362
    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. :-)
    *Cela*

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, 01: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, 04:45 PM
  4. Classes inheretance problem...
    By NANO in forum C++ Programming
    Replies: 12
    Last Post: 12-09-2002, 02:23 PM
  5. string handling
    By lessrain in forum C Programming
    Replies: 3
    Last Post: 04-24-2002, 07:36 PM

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