Archived

This topic is now archived and is closed to further replies.

quick question about char arrays

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

ok, to change a string into a char we use the c_str function. how do i change a char array into a string? thank you.

Share this post


Link to post
Share on other sites
Something like...

std::string MyString;
char MyCharArray[] = "Hello!";

MyString = MyCharArray;

This should work, as I''m pretty sure std::string has an overloaded operator to assign its contents from a character array. If not, it damn well should!


Helpful links:
How To Ask Questions The Smart Way | Google can help with your question | Search MSDN for help with standard C or Windows functions

Share this post


Link to post
Share on other sites
thanks, i''ll try it.
however, i was able to solve
my problem by hammering away with the
string class.

but its always nice to know for future
reference.

thank you.

Share this post


Link to post
Share on other sites
quote:
Original post by Anonymous Poster
A string *is* a char array.
string a("Hello"), b("World"), c;
c = a + '' '' + b;
cout << c;

While a string may use a character array internally, that knowledge doesn''t help much when you want to copy a character array into a string.

Share this post


Link to post
Share on other sites