Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

Visual Studio 2003 convert System::String to char array

Managed C++ string array

  • Please log in to reply
1 reply to this topic

#1 karateboy02

karateboy02

    CC Lurker

  • Just Joined
  • Pip
  • 6 posts

Posted 27 July 2007 - 06:00 AM

I am trying to convert from a System::String to a char array. I have found a code snippet that works in Visual Studio 2005 but when I try to run the same exact code in Visual Studio 2003 I get several errors. The code looks like:


System::String *orig = this->textBox1->Text;
pin_ptr<const wchar_t> wch = PtrToStringChars(orig);

size_t origsize = wcslen(wch) + 1;
const size_t newsize = 100;
size_t convertedChars = 0;
char nstring[newsize];
wcstombs_s(&convertedChars, nstring, origsize, wch, _TRUNCATE);


Where nstring should be where the string ends up. The errors that I get are:

(143): error C2065: 'pin_ptr' : undeclared identifier
(143): error C2059: syntax error : 'const'
(146): error C2065: 'wch' : undeclared identifier
(150): error C2065: '_TRUNCATE' : undeclared identifier
(150): error C3861: 'wcstombs_s': identifier not found, even with argument-dependent lookup
(150): error C3861: 'wch': identifier not found, even with argument-dependent lookup

Any help would be much appreciated.
  • 0

#2 kernelcoder

kernelcoder

    CC Devotee

  • Expert Member
  • PipPipPipPipPipPip
  • 990 posts
  • Location:Dhaka
  • Programming Language:C, Java, C++, C#, Visual Basic .NET
  • Learning:Objective-C, PHP, Python, Delphi/Object Pascal

Posted 24 April 2012 - 07:47 PM

It is better to use String^ rather than String*. It seems it is not there in VS 2003 -- read here http://msdn.microsof...e(v=vs.80).aspx. I mean the pn_ptr, the wcstombs_s methods are not supported in VS 2003. You can use the standard c++ library version (wcstombs) rather than MS version (wcstombs_s).
  • 0





Also tagged with one or more of these keywords: Managed C++, string, array

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download