473,238 Members | 1,931 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,238 software developers and data experts.

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 1695

"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: ceo | last post by:
Hi, Following is a program that doesn't give the expected output, not sure what's wrong here. I'm adding the size of derived class to the base class pointer to access the next element in the...
22
by: Alex Fraser | last post by:
From searching Google Groups, I understand that void pointer arithmetic is a constraint violation, which is understandable. However, generic functions like qsort() and bsearch() must in essence do...
6
by: Francois Grieu | last post by:
Are these programs correct ? #include <stdio.h> unsigned char a = {1,2}; int main(void) { unsigned char j; for(j=1; j<=2; ++j) printf("%u\n", *( a+j-1 )); return 0; }
3
by: randomtalk | last post by:
hello everyone! Well, recently i've been trying to pick up c and see what is pointer all about (been programming in lisp/python for the better part of my last two years).. mmm.. I'm currently...
27
by: Erik de Castro Lopo | last post by:
Hi all, The GNU C compiler allows a void pointer to be incremented and the behaviour is equivalent to incrementing a char pointer. Is this legal C99 or is this a GNU C extention? Thanks in...
7
by: barikat | last post by:
int a; int *Ptr1, *Ptr2; Ptr1 = a; Ptr1++; Ptr2 = a; printf("Ptr1 : %p\n", Ptr1); printf("Ptr2 : %p\n\n", Ptr2);
26
by: Bill Reid | last post by:
Bear with me, as I am not a "professional" programmer, but I was working on part of program that reads parts of four text files into a buffer which I re-allocate the size as I read each file. I...
41
by: Summercool | last post by:
Can we confirm the following? also someone said, Java also has "reference" like in C++, which is an "implicit pointer": Pointer and Reference --------------------- I am starting to see what...
19
by: =?iso-8859-1?b?VG9t4XMg0yBoyWlsaWRoZQ==?= | last post by:
Coming originally from C++, I used to do the likes of the following, using a pointer in a conditional: void Func(int *p) { if (p) { *p++ = 7; *p++ = 8;
25
by: Ioannis Vranos | last post by:
Are the following codes guaranteed to work always? 1. #include <iostream> inline void some_func(int *p, const std::size_t SIZE) {
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.