Jump to content
  • Advertisement
Sign in to follow this  
raptorstrike

string - char *solved*

This topic is 5416 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

how would you do this (is there a pre-made functino for this) if not what kind of things could i do to store what a string = into a char whatever[]; [Edited by - raptorstrike on September 24, 2004 2:42:02 PM]

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
You mean like:

string MyString = "Stuff";
cout << MyString.c_str() << endl;

Or do you mean something else?

Share this post


Link to post
Share on other sites
Constant string:

char msg[] = "Message"; // Size is automatic



Pointer to string:

char msg[256]; // MUST be large enough to hold text plus one byte!
char *pString = "Message";
strcpy(msg, pString);



C++ string:

char msg[256]; // Again, must have enough room
std::string str("Message");
strcpy(msg, str.c_str());


Share this post


Link to post
Share on other sites
ok thanks alot you guys

wait from what i can tell im assigning

charArray[] to something

i want to do it the other way around

this is what i have so far

char scorestore[6];
char *pPrint;
string Print = strcpy(scorestore, pPrint);

Share this post


Link to post
Share on other sites
Technically, the call to the std::string.c_str() method will give you access to the raw character bytes in the string.

You can then use this method to copy a std::string to a char[] array using the strcpy() function. Just make sure that you allocate enough memory for the copy.

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!