0

I am very new to c++.

Say I have this:

char arrOne[10];
char arrTwo[10];
char arrThree[10];

How can I create an array where each element in the array holds a character array like above?

The goal is to be able to call upon the index of the array of arrays to grab one of these character arrays when needed.

Keep in mind. I can ONLY use iostream.

7
  • An array of arrays? An array of pointers? Or better yet, an array of std::string objects. Commented Sep 14, 2014 at 16:04
  • Like I said I can't use string.h I can only use iostream. I don't know a whole lot about arrays in c++. I know it involves pointers, that is why I need some guidance here. Commented Sep 14, 2014 at 16:05
  • @itdoesntwork I tried that and it didn't seem to work. Commented Sep 14, 2014 at 16:06
  • @Smartypants, Good thing std::string isn't in string.h. Arrays don't have to involve pointers, either. std::array is as good as any other array and has nothing to do with pointers. Commented Sep 14, 2014 at 16:06
  • I have to use character arrays instead of strings. It is part of the project description :/ Commented Sep 14, 2014 at 16:08

2 Answers 2

2

You could create a char pointer array

char * array[3];

char arrOne[10]
char arrTwo[10]
char arrThree[10]

array[0] = arrOne;
array[1] = arrTwo;
array[2] = arrThree;

To access arrayOne ,for example, use array[0].

Sign up to request clarification or add additional context in comments.

Comments

0

Hello I think you need to use a for/while loop to access each element in an array for example

char array[10] = "hello";

int i = 0;

while (i != '\0')
{
 if( array[i] = 'l')
 {
   array[i] = 'x';
 }
i++;
}
 cout <<"new array string" << array<<endl;

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.