Solved

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

Posted on 2006-06-27
12
769 Views
Last Modified: 2008-02-01
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!
0
Comment
Question by:demilune
  • 5
  • 5
  • 2
12 Comments
 
LVL 11

Expert Comment

by:Jase-Coder
ID: 16999006

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

Author Comment

by:demilune
ID: 16999018
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
 
LVL 11

Expert Comment

by:Jase-Coder
ID: 16999037
try removing the .ToString
0
Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

 
LVL 11

Expert Comment

by:Jase-Coder
ID: 16999041
or do

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

Author Comment

by:demilune
ID: 16999047
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
 

Author Comment

by:demilune
ID: 16999049
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
 

Author Comment

by:demilune
ID: 16999072
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
 
LVL 22

Accepted Solution

by:
mahesh1402 earned 250 total points
ID: 16999074
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
 

Author Comment

by:demilune
ID: 16999080
Mahesh...

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

Thanks alot both of you for your help!
0
 
LVL 11

Expert Comment

by:Jase-Coder
ID: 16999084
I dont use managed C++ but I'll take a look now.
0
 
LVL 22

Expert Comment

by:mahesh1402
ID: 16999087
demilune you have accepted wrong answer in MFC TA for this Q.. i think you need to change it
0
 
LVL 11

Expert Comment

by:Jase-Coder
ID: 16999135
this works:

char szText[100] = "Jason";
textBox1->Text = gcnew String(szText);
0

Featured Post

ScreenConnect 6.0 Free Trial

Explore all the enhancements in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

The following diagram presents a diamond class hierarchy: As depicted, diamond inheritance denotes when two classes (e.g., CDerived1 and CDerived2), separately extending a common base class (e.g., CBase), are sub classed simultaneously by a fourt…
In Easy String Encryption Using CryptoAPI in C++ (http://www.experts-exchange.com/viewArticle.jsp?aid=1193) I described how to encrypt text and recommended that the encrypted text be stored as a series of hexadecimal digits -- because cyphertext may…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

778 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question