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++ / October 2007

Tip: Looking for answers? Try searching our database.

Pointer Arithmetic in VC.net

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Dipesh_Sharma - 04 Oct 2007 06:04 GMT
Hi all,
I am porting my code in VC++ to VC.net i.e managed. I have seen somewhere
that i need to convert my char* to String*, but String * doesnt perform
pointer arithmetic like String* p; *p++=' ';
So please suggest as to what i have to do? Am i doing wrong by converting
char* to String* in managed VC.net.
Thanks,
Dipesh.
Ben Voigt [C++ MVP] - 04 Oct 2007 15:44 GMT
> Hi all,
> I am porting my code in VC++ to VC.net i.e managed. I have seen somewhere
[quoted text clipped - 4 lines]
> Thanks,
> Dipesh.

Which version of VC?  C++/CLI (2005) handles this very differently from
2002, 2003.  If you're not using 2005, upgrade now because of design bugs in
Managed Extensions for C++.
Dipesh_Sharma - 05 Oct 2007 10:03 GMT
Hi Ben,
I am working on VS 2005, my problem is that : i am porting my code from VC++
to VC.net to make it .Net compatible. And i have learnt that char* are not
used in .Net instead we use String*. But my code is having extensive use of
char* in function calls, pointer arithmetic etc. So please suggest me as to
how  i should make this change of char* to String* : in pointer arithmetic
i.e char *p++; and in function caling..
Please help me out..
Thanks.

> > Hi all,
> > I am porting my code in VC++ to VC.net i.e managed. I have seen somewhere
[quoted text clipped - 8 lines]
> 2002, 2003.  If you're not using 2005, upgrade now because of design bugs in
> Managed Extensions for C++.
Ben Voigt [C++ MVP] - 05 Oct 2007 18:59 GMT
> Hi Ben,
> I am working on VS 2005, my problem is that : i am porting my code from
[quoted text clipped - 8 lines]
> Please help me out..
> Thanks.

Don't.  "String*" doesn't exist, you cannot have a native pointer to a
garbage collected object.

To get a pointer to the characters inside the String:

String^ s;

interior_ptr<const wchar_t> p = PtrToStringChars(s);

(Note that .NET strings are immutable, you are not permitted to overwrite
them in place, also they are Unicode).

If you need to convert to ASCII (single byte character sequences), there's
Marshal::PtrToStringAnsi.  Also the String constructor accepts a character
pointer, so you can do

wchar_t* p = L"My native Unicode string";
String^ s = gcnew String(p);

>> > Hi all,
>> > I am porting my code in VC++ to VC.net i.e managed. I have seen
[quoted text clipped - 11 lines]
>> in
>> Managed Extensions for C++.

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.