DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Newsletter
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • Detecting Duplicates With Machine Learning in 2026: From String Metrics to Embeddings and LLMs
  • Replacing JSON With Protobuf in Your Microservice Mesh: A Zero-Downtime Migration Blueprint
  • Fix the Target, Precompute Once: A Backend-Free Word-Ladder Solver With a BFS Distance Field
  • Swift: Master of Decoding Messy JSON

Trending

  • Engineering Responsible AI for High-Stakes Financial Applications
  • PWA on iOS, Part 6: Performance, Rendering, and Keyboard
  • AI Didn't Replace Software Engineering; It Changed the Bottleneck
  • Getting Started With Weaviate: Building AI-Powered Search Applications With Java

Draft This article hasn't been published, so readers can't see it.

In moderation This article is waiting for review, so readers can't see it yet.

Deleted This article has been deleted, so readers can't see it.

  1. DZone
  2. Coding
  3. JavaScript
  4. Converting System Strings Into Standard Strings

Converting System Strings Into Standard Strings

Learn about system strings and check out this solution to a common problem when working with C++/CLI: converting System::string^ into std::string.

By 
Orcun Yilmaz
·
Aug. 27, 17 · Tutorial
Post on X (opens in a new tab) Share on LinkedIn (opens in a new tab)
7.3K Views

Join the DZone community Save articles, join the discussion, and download Refcards and Trend Reports with a free account.

Join for free Already a member? Log in

C++/CLI (C++ modified for Common Language Infrastructure) is a language specification created by Microsoft and intended to supersede Managed Extensions for C++ that is used in Visual C++. Which means, you can say that C++/CLI is a C++ extension. It is a complete revision that aims to simplify the older Managed C++ syntax, which is now deprecated. So I wanted to use this extension a bit to see what I can do with it.

And I must say that it is awesome to use C++ and also C# features together. It’s like you are writing C++, but when you bored, you can switch into C#.

In this post, I am going to show a solution to the problem of converting System::string^ into std::string. You will face this problem so many times if you decide to use C++/CLI.

What Are System Strings?

System Strings are the types that commonly used in CLR projects. When you made a research on the web, you will see that most of the projects are developed with System::strings^ instead of std::strings.

The difference between System Strings and Standard Strings is about the mapping types into another. In some languages, while you are mapping your variable types into 32 bit, in some languages you can map them into 64 bit. So the fact that using std::string or System::string^ makes no difference is well established.

Is It Still Better to Use String Instead of System.String?

There is no agreed answer on this. It is up to you. For me, I needed to use std::string in my project, so I’ve developed a function to do this. If you needed to use std::string instead of System::string^ like me, you can check out this function:

using System::Runtime::InteropServices::Marshal;

static std::string toStandardString(System::String^ string)
{
 System::IntPtr pointer = Marshal::StringToHGlobalAnsi(string);
 char* charPointer = reinterpret_cast<char*>(pointer.ToPointer());
 std::string returnString(charPointer, string->Length);
 Marshal::FreeHGlobal(pointer);

 return returnString;
}
Strings

Published at DZone with permission of Orcun Yilmaz. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • Detecting Duplicates With Machine Learning in 2026: From String Metrics to Embeddings and LLMs
  • Replacing JSON With Protobuf in Your Microservice Mesh: A Zero-Downtime Migration Blueprint
  • Fix the Target, Precompute Once: A Backend-Free Word-Ladder Solver With a BFS Distance Field
  • Swift: Master of Decoding Messy JSON

Partner Resources

×

Comments

Loading comments

The comments didn't load

Please try again in a moment.

Likes

Loading

The next likes didn't load. Please try again.

The likes didn't load

Please try again in a moment.

See who liked this

Log in or join DZone for free to see who liked this article.

Log in Join for free
  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook