Connecting Tech Pros Worldwide Forums | Help | Site Map

C++ .NET convert character array to String

Newbie
 
Join Date: Jul 2007
Posts: 11
#1: Jul 3 '07
I am working on Visual C++ 2005. I have a character array (array<Char>) and want to convert it to string. I know I can do this with the String constructon (gcnew String(charArray)), but is there no other way without allocating memory? I have in mind the GetString method of System::Text::Encoding::ASCII but couldnt manage to do what I wanted to do.
Thanks in advance for any help.

vanc's Avatar
Expert
 
Join Date: Mar 2007
Posts: 202
#2: Jul 4 '07

re: C++ .NET convert character array to String


char[] arrayofchar;
string temp;
foreach(char c in arrayofchar)
temp += c;

:D, cheers.
Newbie
 
Join Date: Jul 2007
Posts: 11
#3: Jul 5 '07

re: C++ .NET convert character array to String


That was nice thanks
Reply