string append

hi ,i am trying to append some strings using 2 string array and for loop but i couldnt make it

something like this


#include "stdafx.h"
#include "stdlib.h"
#include "iostream"
using namespace std;

#define size 20
int _tmain(int argc, _TCHAR* argv[])
{
string dd[size]={"woody","tom"};
string d[size]={"allen","cruse"};
for(int i=0;i<=4;i++){
string temp[size];
for(int k=0;k<=4;k++){

dd[i]+=d[k];

cout<<dd;
}
}

system("pause");
}

Use code tags, the <> button!

I am not sure what you are trying to do here but.

Using the overloaded operator + works like this.

1
2
3
4
5
string string1 = "Nr1";
string string2 = "Nr2";
string string3 = string1 + string2;

cout << string3 << endl;


Output:
Nr1Nr2

You cant add the arrays in the way that i think you are trying to do.
Then you need to use.

String[index where you want to copy] = String[index what you want to copy]

Hope this helped.

Good luck!
Topic archived. No new replies allowed.