Pointer Arithmetic in VC.net

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • =?Utf-8?B?RGlwZXNoX1NoYXJtYQ==?=

    #1

    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.
  • Ben Voigt [C++ MVP]

    #2
    Re: Pointer Arithmetic in VC.net


    "Dipesh_Sha rma" <DipeshSharma@d iscussions.micr osoft.comwrote in message
    news:B1314A47-B8B8-4218-AA3C-D5115821A7B2@mi crosoft.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++.


    Comment

    • =?Utf-8?B?RGlwZXNoX1NoYXJtYQ==?=

      #3
      Re: Pointer Arithmetic in VC.net

      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_Sha rma" <DipeshSharma@d iscussions.micr osoft.comwrote in message
      news:B1314A47-B8B8-4218-AA3C-D5115821A7B2@mi crosoft.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++.
      >
      >
      >

      Comment

      • Ben Voigt [C++ MVP]

        #4
        Re: Pointer Arithmetic in VC.net


        "Dipesh_Sha rma" <DipeshSharma@d iscussions.micr osoft.comwrote in message
        news:3B5C4FE9-779E-4B6F-999C-93E60BE32774@mi crosoft.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<co nst wchar_tp = PtrToStringChar s(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::PtrToS tringAnsi. 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 " <DipeshSharma@d iscussions.micr osoft.comwrote in message
        >news:B1314A4 7-B8B8-4218-AA3C-D5115821A7B2@mi crosoft.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++.
        >>
        >>
        >>

        Comment

        Working...