468,309 Members | 1,201 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,309 developers. It's quick & easy.

Pointer Arithmetic in VC.net

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.
Oct 4 '07 #1
3 1512

"Dipesh_Sharma" <Di**********@discussions.microsoft.comwrote in message
news:B1**********************************@microsof t.com...
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.
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++.
Oct 4 '07 #2
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.

"Ben Voigt [C++ MVP]" wrote:
>
"Dipesh_Sharma" <Di**********@discussions.microsoft.comwrote in message
news:B1**********************************@microsof t.com...
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.

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++.
Oct 5 '07 #3

"Dipesh_Sharma" <Di**********@discussions.microsoft.comwrote in message
news:3B**********************************@microsof t.com...
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.
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_tp = 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);
>
"Ben Voigt [C++ MVP]" wrote:
>>
"Dipesh_Sharma" <Di**********@discussions.microsoft.comwrote in message
news:B1**********************************@microso ft.com...
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.

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++.
Oct 5 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

8 posts views Thread by ceo | last post: by
22 posts views Thread by Alex Fraser | last post: by
6 posts views Thread by Francois Grieu | last post: by
3 posts views Thread by randomtalk | last post: by
27 posts views Thread by Erik de Castro Lopo | last post: by
7 posts views Thread by barikat | last post: by
41 posts views Thread by Summercool | last post: by
19 posts views Thread by =?iso-8859-1?b?VG9t4XMg0yBoyWlsaWRoZQ==?= | last post: by
25 posts views Thread by Ioannis Vranos | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.