Help Converting char to string

I am fairly new to C++ and need help appending a charcter from a string.

char Buffer[65];
contains:
0x00 0x40 0x01 0x02 0x00 0x04 0x02 0x02 .......

I have the following code

String^ s = gcnew String("");
String^ spc = gcnew String(":");
char a;

a=Buffer[1];
s+= a; //How can I get the character representation here?
s+= "x";
s = s->Concat(s , spc);
for(int j =2; j < 6 ; ++j){
if (Buffer[j]!=0xFF)
{
s = s->Concat(s , Buffer[j]); //note converts the BCD values to its numeric equivalents
}
else continue;
}
SetTimeResponse_lbl->Text = s;

The output in SetTimeResponse_lbl becomes

64x:1204

I understand S-> concat translates the character variable into its numeric representation. But what I want is to translate
Buffer[1] into its character representation, so the output should be:

@x:1204

How can I do that? & Help appreciated.
The following function works:

String^ StringFromChar(char b)
{ System::Text::Encoding^ encoding = System::Text::Encoding::UTF8;
array<Byte>^ h = gcnew array<Byte>(1){64};
h[0]=b;
return encoding->GetString(h);
}

So, in above code, replace:

s+= a; //How can I get the character representation here?

by

s+=StringFromChar(a);
Let me know if I am missing something, but to answer the question of getting the string representation of a char array, you could simply cast it:
 
cout << (string)Buffer;


I noticed @ was spit out given the character code of 64, but do you want it to be represented in another way?
Last edited on
Just a question. What exactly is String^ ?
Vlykarye, that is a good question. I think it is just an alias to * in the Common Language Infrastructure.

Someone else could elaborate. I wouldn't mind to hear more.
Ah. I guessed that is what it was, but.. Sounds interesting.
No, a pointer is still a pointer in CLI. ^ denotes a garbage collected handle.
Thank you all for your remarks.

To: cantide5ga
"
Let me know if I am missing something, but to answer the question of getting the string representation of a char array, you could simply cast it:

cout << (string)Buffer;

I noticed @ was spit out given the character code of 64, but do you want it to be represented in another way?
"

My Buffer contains a mixture of integer values and characters. So some need to be translated into characters (in the example, the @ character indeed) and others need to be converted from their binary value to a decimal representation.

Thanks again
Last edited on
Topic archived. No new replies allowed.