473,320 Members | 1,948 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,320 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 1704

"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) {
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
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...
1
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...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.