Jump to content
  • Advertisement
Sign in to follow this  
Bluseed

String Arrays.

This topic is 4353 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
Advertisement
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.

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
Quote:
Original post by wildex999
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?
Perhaps you mean something like this:
char* myArray[2];
myArray[0] = "Name1";
myArray[1] = "Name2";
In any case, this is more idiomatic for C, whereas the OP specified C++.

Share this post


Link to post
Share on other sites
Quote:
Original post by Bluseed
hmmm 4 some reason those dont work for me?
Post the code that doesn't work, along with whatever errors you're getting.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!