Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / Managed C++ / February 2007

Tip: Looking for answers? Try searching our database.

I am a fresh Visual C++ .NET Developer. Convert char[1024] to System::String

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
simon@simon-john.com - 21 Feb 2007 00:41 GMT
I am a fresh Visual C++ .NET Developer. Can you kindly guide me for
How to Convert char[1024] to System::String

I am using windows forms and trying to set a text value referencing
the method className() of  an object of class HetConvert (my own) this
returns a char - which as you can see from the code below I am trying
to pass to  label1->Text - but this expects a String^

any clues anyone

Thanks

----------------------

public: System::Void label1_Click(System::Object^  sender,
System::EventArgs^  e) {

HetConvert *hetcnv = new HetConvert ( "Hetcnv" );

char outputString[1024] ;

strcpy(outputString, (hetcnv->className()+ '\0') ) ;

label1->Text= outputString ;

        }
William DePalo [MVP VC++] - 21 Feb 2007 01:32 GMT
>I am a fresh Visual C++ .NET Developer. Can you kindly guide me for
> How to Convert char[1024] to System::String

The short answer is that you construct one.

Take a look at this page for more info:

http://blogs.msdn.com/slippman/archive/2004/06/02/147090.aspx

where you will find this

   void F( const char* s )
   {
       String^ s1 = gcnew String( s );
   }

Regards,
Will
www.ivrforbeginners.com
Ben Voigt - 21 Feb 2007 14:40 GMT
>I am a fresh Visual C++ .NET Developer. Can you kindly guide me for
> How to Convert char[1024] to System::String
[quoted text clipped - 18 lines]
>
> strcpy(outputString, (hetcnv->className()+ '\0') ) ;

And what do you think that line does?  What data type does className()
return?  You are adding a character constant zero, if className() is a char*
(which it must be if passed to strcpy), then the '\0' is promoted to
(ssize_t)0, which adds a zero offset to the pointer.

You aren't appending a null character to the string, and you're risking a
buffer overflow and reducing performance for no purpose.

> label1->Text= outputString ;

Get rid of the temporary and use just
label1->Text = gcnew String(hetcnv->className());

> }
Gary - 22 Feb 2007 21:55 GMT
I recommend looking up information on pointers and how strings work in
unmanaged C++. Native string types are memory addresses and adding them
does not append the strings. You can use the Standard Template Library
or MFC string class to make this easier.

> I am a fresh Visual C++ .NET Developer. Can you kindly guide me for
> How to Convert char[1024] to System::String
[quoted text clipped - 22 lines]
>
>         }

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.