string array.

AOA,

I was just trying to get easy with structure,i came across this problem.

Can we have an array of string?

like

string names[6];

Although there is no problem while compiling this one but the problem was when i tried to manipulate it with fuctions like,

string id;

and then in the for loop.

strcpy(id,names[i]);

there was an error in compiling indication primary error before ','.

I am hoping a good n early answer for this question.
Short answer: Yes.

Long answer: Yes, but you have to understand that a string is a container of characters. So when you handle the string array, you have to treat it like it's actually a container of containers, which it is. In fact, it's 6 containers. You can treat it exactly the same way as an array of vectors or an array of deques.
but beside please also tell me how to use the strcpy function then?
Your question is gramatically incorrect; Usually that's not an issue, but in this case it's so bad that I can't make out what you're saying.
I am just asking if i can use something like
string abs[4];
why i am unable to copy it into another string.
string a;
strcpy(a,abs[1]);
is not working.
Never use strcpy with strings. strcpy is for use with char arrays. Same with all the other strxxx functions like strcmp, strcat, etc. Never ever use them with strings.

Just use the assignment operator:

1
2
3
4
5
string abs[4];
string a;

// strcpy(a,abs[1]);  //< -BAD
a = abs[1];  // <- good 

Topic archived. No new replies allowed.