outputing character array to a text box using vc++ 2005 express

I apologize for my ignorance, but...

I have a char array that I need to output to a textbox. I have this now...

     Memo1->AppendText("    Item Name: " + Msg.ItemName8[0].ToString() + "\r\n");

Obviously, this only outputs the ascii value stored in [0] of the array. What is the best way to output the full array in ascii characters???

Code is helpful here :)

Thanks!
demiluneAsked:
Who is Participating?
 
mahesh1402Commented:
have you tried this ? as i suggested

unsigned char ItemName[16];

....

std::string cppString;

cppString = (const char *)ItemName;

 Memo1->AppendText(new System::String(cppString.c_str());  <=====
0
 
Jase-CoderCommented:

Memo1->AppendText("    Item Name: " + Msg.ItemName8.ToString() + "\r\n");
0
 
demiluneAuthor Commented:
Jase...

That is what I had thought too, but I can't get around this compiler error:

error C2228: left of '.ToString' must have class/struct/union type is 'unsigned char [16]'
0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
Jase-CoderCommented:
try removing the .ToString
0
 
Jase-CoderCommented:
or do

Memo1->AppendText("    Item Name: " + String(Msg.ItemName8) + "\r\n");
0
 
demiluneAuthor Commented:
Tried that too... I get the following:

error C2679: binary '+' : no operator found which takes a right-hand operand of type 'unsigned char *' (or there is no acceptable conversion)
        could be 'built-in C++ operator+(volatile const System::Object ^, volatile const System::String ^)'
        or 'built-in C++ operator+(volatile const System::String ^, volatile const System::Object ^)'
        or 'built-in C++ operator+(volatile const System::String ^, volatile const System::String ^)'
        while trying to match the argument list '(System::String ^, unsigned char *)'
0
 
demiluneAuthor Commented:
If I try the String( ... ) option, I get:

error C2440: '<function-style-cast>' : cannot convert from 'unsigned char [16]' to 'System::String'
        No constructor could take the source type, or constructor overload resolution was ambiguous
0
 
demiluneAuthor Commented:
I ended up doing the following and it is working...

unsigned char ItemName[16];

....

std::string cppString;

cppString = (const char *)ItemName;

 Memo1->AppendText(gcnew System::String(cppString.c_str()));  <=====
0
 
demiluneAuthor Commented:
Mahesh...

That worked, I only had to replace the "new" with "gcnew"

Thanks alot both of you for your help!
0
 
Jase-CoderCommented:
I dont use managed C++ but I'll take a look now.
0
 
mahesh1402Commented:
demilune you have accepted wrong answer in MFC TA for this Q.. i think you need to change it
0
 
Jase-CoderCommented:
this works:

char szText[100] = "Jason";
textBox1->Text = gcnew String(szText);
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.