String Arrays.
Can someone point me in the right direction??
Im trying to put some names in an array!
myArray[3]
myArray[0] = "John"
myArray[1] = "Joe"
myArray[2] = "Jose"
myArray[3] = "Jill"
printf("%s", myArray[2])
output:
Jose
press any key to continue...
*********
(whatever! you know)
Ive been looking around but cant find anything on it im gonna keep looking though. thx
The C++ equivalent of the (presumably pseudo-) code that you posted might look something like this:
std::vector<std::string> myArray(4);myArray[0] = "John";myArray[1] = "Joe";myArray[2] = "Jose";myArray[3] = "Jill";std::cout << myArray[2] << std::endl;
If any of this looks unfamiliar, just ask.
I am just guessing here, but won't this work?
char myArray[3][20];
myArray[0][]="Name1\0";
myArray[1][]="Name2\0";
Something like that?
char myArray[3][20];
myArray[0][]="Name1\0";
myArray[1][]="Name2\0";
Something like that?
Quote:Original post by wildex999Perhaps you mean something like this:
I am just guessing here, but won't this work?
char myArray[3][20];
myArray[0][]="Name1\0";
myArray[1][]="Name2\0";
Something like that?
char* myArray[2];myArray[0] = "Name1";myArray[1] = "Name2";
In any case, this is more idiomatic for C, whereas the OP specified C++.
Quote:Original post by BluseedPost the code that doesn't work, along with whatever errors you're getting.
hmmm 4 some reason those dont work for me?
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement