<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>System::String -&gt; std::string</title><link>http://blogs.msdn.com/slippman/archive/2004/06/02/147090.aspx</link><description>A reader asks, Sender: Erik Brendengen Is there an easy way to convert from String^ to std::string? Does String ^s = std::string( &amp;#8220;bla&amp;#8221;).c_str(); work the other way? This is a FAQ, one that I myself bumped into when I had to pass a System::String</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>re: System::String -&gt; std::string</title><link>http://blogs.msdn.com/slippman/archive/2004/06/02/147090.aspx#147763</link><pubDate>Thu, 03 Jun 2004 17:27:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:147763</guid><dc:creator>David Larsson</dc:creator><description>Are there any plans to, ahem, extend std::string to include constructors and extraction methods for String^, like ATL::CString currently has? &lt;br&gt;As a sidenote, this is not the first time I find myself wanting one or two features from CString in std::string, to make the decision for which of the two classes to use for a native Windows C++ application a bit easier...&lt;br&gt;Either way, I'm really looking forward to the new C++/CLI. Actually, the /clr switch works amazingly well even today.</description></item><item><title>re: System::String -&gt; std::string</title><link>http://blogs.msdn.com/slippman/archive/2004/06/02/147090.aspx#148847</link><pubDate>Fri, 04 Jun 2004 22:01:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:148847</guid><dc:creator>Anson Tsao [MSFT]</dc:creator><description>In Whidbey we'll be supplying much more direct approach to do this type of marshalling via a library.&lt;br&gt;&lt;br&gt;void F( String^ s )&lt;br&gt;{&lt;br&gt;   string s1 = marshal_to&amp;lt;string&amp;gt;( s );&lt;br&gt;   String^ s2 = marshal_to&amp;lt;String^&amp;gt;( s1 );&lt;br&gt;}&lt;br&gt;&lt;br&gt;If you already have a char*, and want to get a System::String from it, all you have to do is this:&lt;br&gt;&lt;br&gt;void F( const char* s )&lt;br&gt;{&lt;br&gt;    String^ s1 = gcnew String( s );&lt;br&gt;}</description></item><item><title>re: System::String -&gt; std::string</title><link>http://blogs.msdn.com/slippman/archive/2004/06/02/147090.aspx#158312</link><pubDate>Thu, 17 Jun 2004 16:26:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:158312</guid><dc:creator>stan lippman</dc:creator><description>as david larsson's ahem indicates, extending the standard ISO-C++ string independent of a standard's body is, i think, unlikely at this point. however, as anson's mail indicates, there is lots of thought being given on how to help users interoperate between the native and managed platforms, and david's request for support in this is not at all unreasonable.</description></item><item><title>re: System::String -&gt; std::string</title><link>http://blogs.msdn.com/slippman/archive/2004/06/02/147090.aspx#158533</link><pubDate>Thu, 17 Jun 2004 19:16:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:158533</guid><dc:creator>stan lippman</dc:creator><description>Yves Dolce -- the conscience of the blogs -- rightly pointed out that they two conversion samples needlessly prolong the pinning of the internal System::Char array of the String, and has proposed the following preferred alternatives, &lt;br&gt;&lt;br&gt;bool To_CharStar( String^ source, char*&amp;amp; target )&lt;br&gt;&lt;br&gt;{&lt;br&gt;&lt;br&gt;    int len = (( source-&amp;gt;Length+1) * 2);&lt;br&gt;&lt;br&gt;    target = new char[ len ];&lt;br&gt;&lt;br&gt;    pin_ptr&amp;lt;const wchar_t&amp;gt; wch = PtrToStringChars( source );&lt;br&gt;&lt;br&gt;    return wcstombs( target, wch, len ) != -1;&lt;br&gt;&lt;br&gt;}&lt;br&gt;&lt;br&gt; &lt;br&gt;&lt;br&gt;bool To_string( String^ source, string &amp;amp;target )&lt;br&gt;&lt;br&gt;{&lt;br&gt;&lt;br&gt;    int len = (( source-&amp;gt;Length+1) * 2);&lt;br&gt;&lt;br&gt;    char *ch = new char[ len ];&lt;br&gt;&lt;br&gt;    bool result ;&lt;br&gt;&lt;br&gt;    {&lt;br&gt;&lt;br&gt;        pin_ptr&amp;lt;const wchar_t&amp;gt; wch = PtrToStringChars( source );&lt;br&gt;&lt;br&gt;        result = wcstombs( ch, wch, len ) != -1;&lt;br&gt;&lt;br&gt;    }&lt;br&gt;&lt;br&gt;    target = ch;&lt;br&gt;&lt;br&gt;    delete ch;&lt;br&gt;&lt;br&gt;    return result;&lt;br&gt;&lt;br&gt;}&lt;br&gt;&lt;br&gt;</description></item><item><title>re: System::String -&gt; std::string</title><link>http://blogs.msdn.com/slippman/archive/2004/06/02/147090.aspx#171705</link><pubDate>Fri, 02 Jul 2004 12:00:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:171705</guid><dc:creator>Jonathan Pryor</dc:creator><description>In To_string(), shouldn't&lt;br&gt;&lt;br&gt;delete ch;&lt;br&gt;&lt;br&gt;actually be&lt;br&gt;&lt;br&gt;delete[] ch;&lt;br&gt;&lt;br&gt;Since you're allocating an array, you really should use the array deletion expression...</description></item><item><title>re: System::String -&gt; std::string</title><link>http://blogs.msdn.com/slippman/archive/2004/06/02/147090.aspx#175574</link><pubDate>Wed, 07 Jul 2004 18:39:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:175574</guid><dc:creator>stan lippman</dc:creator><description>you are correct. it is a bad habit for an old dog who was programming with the language before this was added, and of course in current implementations, its absence is actually both non-fatal and possibly more efficient.</description></item><item><title>Managed C++ - Page 3 | keyongtech</title><link>http://blogs.msdn.com/slippman/archive/2004/06/02/147090.aspx#9360932</link><pubDate>Thu, 22 Jan 2009 04:06:37 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9360932</guid><dc:creator>Managed C++ - Page 3 | keyongtech</dc:creator><description>&lt;p&gt;PingBack from &lt;a rel="nofollow" target="_new" href="http://www.keyongtech.com/2327213-managed-c/3"&gt;http://www.keyongtech.com/2327213-managed-c/3&lt;/a&gt;&lt;/p&gt;
</description></item><item><title>I am a fresh Visual C++ .NET Developer. Convert char[1024] to System::String | keyongtech</title><link>http://blogs.msdn.com/slippman/archive/2004/06/02/147090.aspx#9365322</link><pubDate>Thu, 22 Jan 2009 12:17:07 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9365322</guid><dc:creator>I am a fresh Visual C++ .NET Developer. Convert char[1024] to System::String | keyongtech</dc:creator><description>&lt;p&gt;PingBack from &lt;a rel="nofollow" target="_new" href="http://www.keyongtech.com/737353-i-am-a-fresh-visual"&gt;http://www.keyongtech.com/737353-i-am-a-fresh-visual&lt;/a&gt;&lt;/p&gt;
</description></item></channel></rss>