string concat...sort of

This is a discussion on string concat...sort of within the C++ Programming forums, part of the General Programming Boards category; I know of strcat but what if I have something like. varA varB varC varD and I want one line ...

  1. #1
    Registered User
    Join Date
    Aug 2005
    Posts
    128

    string concat...sort of

    I know of strcat but what if I have something like.
    varA
    varB
    varC
    varD

    and I want one line that looks like:
    stringVal = varA & varB & varC...

    Can it be done?

    Or am I stuck building with strcat?

  2. #2
    Banned
    Join Date
    Jun 2005
    Posts
    594
    your posting in c++
    you shoudl use strings


    Code:
    #include <iostream>
    #include <string>
    
    using namespace std;
    
    int main()
    {
         string var1 = "var1 ";
         string var2 = "var2 ";
         string var3 = "var3 ";
         string var4 = "var4";
         string var5 = var1 + var2 + var3 + var4 + "!";
         cout << var5 << endl;
         cin.get();
         return 0;
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 26
    Last Post: 07-05-2010, 11:43 AM
  2. char Handling, probably typical newbie stuff
    By Neolyth in forum C Programming
    Replies: 16
    Last Post: 06-21-2009, 05:05 AM
  3. Compile Error that i dont understand
    By bobthebullet990 in forum C++ Programming
    Replies: 5
    Last Post: 05-05-2006, 10:19 AM
  4. lvp string...
    By Magma in forum C++ Programming
    Replies: 4
    Last Post: 02-27-2003, 12:03 AM
  5. creating class, and linking files
    By JCK in forum C++ Programming
    Replies: 12
    Last Post: 12-08-2002, 02:45 PM

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