This question is very simple but I can't figure it out, I know how to do it with arrays, but now I need to to it with strings.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
int main()
{
char A[10], B[10];
char C[10]; //the string where we will calculate the sum
cout<<"Enter first string: ";
cin.getline(A, 10); //reading the first string
cout<<"Enter second string: ";
cin.getline(B, 10); //reading the second string
C[10]= A[10] + B[10]; //this doesn't work
cin.getline(C, 10);
cout<<C<<endl;
This piece of code would not work.
1. Arrays use zero based indices. You are therefore accessing somewhere out of you array.
2. The memory allocated for C is too small. As it is taking a sum, it must have space of at least 20.
3. You. must do the assignment index by index.
4. Std::string is a better idesa.