string type to char type with same effect

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • kenneth6
    New Member
    • Mar 2007
    • 79

    string type to char type with same effect

    i am now having:
    string* book=new string[100]; // string array

    in Windows form application (managed code), i am unable to user it !
    how can change it to char type with the same effect and use it in managed code?

    =============== ===

    char * cstr;
    string str ("Please split this phrase into tokens");

    cstr = new char [str.size()+1];
    strcpy (cstr, str.c_str());
  • Laharl
    Recognized Expert Contributor
    • Sep 2007
    • 849

    #2
    Not knowing any managed C++, all I can tell you is that the string class has a c_str() method that returns a null-terminated const char* with the same characters. That is, a C-string.

    Comment

    • weaknessforcats
      Recognized Expert Expert
      • Mar 2007
      • 9214

      #3
      I don't believe you can use any pointers in managed code.

      I think you have to create a String^ using gcnew and copy your data to that.

      There should be info on this in Microsoft's interoperabilit y topics in MSDN.

      Comment

      Working...