char pointer???

Hi I have tried to figured out, but it does not work, please help.
I know that I can do this to store char variables like words, but they are constant.

const char * const name[ 4 ] =
{ "jason", "peter", "mike", "carol" };


But I was wondering if I can store the same but be able to enter with
cin >> *name; ???? because I know I can store it as an array but only one character like
char name[4] = {'m','o','k','e'};

I was thinking that maybe I could use the pointer to store more than one characters per location.

Thanks, I appreciate any comment.
Use a std::vector or a struct for that (a vector is better solution).
Last edited on
or a string. Since, you know, you're dealing with strings:

1
2
3
string name = "moke";

cin >> name;
If you need array you may use
1
2
 unsigned int n(4);
string names[n]


read and write within a loop

1
2
3
4
5
for(unsigned int i = 0 ; i < n; i++){
	// do some thing here with names[i] :-)
	// cin>> names[i] ;
        //cout<< names[i]; or whatever you wish
}


hope it helps
Last edited on
"getline" and string.

C++ provide many good methods than pointer, though it's a very basic concept of C++ and C.

b2ee
Topic archived. No new replies allowed.