<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Code Library &#187; string</title>
	<atom:link href="http://www.ucosoft.com/tag/string/feed" rel="self" type="application/rss+xml" />
	<link>http://www.ucosoft.com</link>
	<description>Free Source Code and Program Tips</description>
	<lastBuildDate>Thu, 22 Jul 2010 05:17:10 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>How to translate among CString,string and char array</title>
		<link>http://www.ucosoft.com/how-to-translate-among-cstringstring-and-char-array.html</link>
		<comments>http://www.ucosoft.com/how-to-translate-among-cstringstring-and-char-array.html#comments</comments>
		<pubDate>Fri, 22 Jun 2007 03:56:19 +0000</pubDate>
		<dc:creator>support</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[How-to]]></category>
		<category><![CDATA[STL]]></category>
		<category><![CDATA[string]]></category>
		<category><![CDATA[Win32/MFC]]></category>

		<guid isPermaLink="false">http://www.ucosoft.com/2007/06/22/how-to-translate-among-cstringstring-and-char-array.html</guid>
		<description><![CDATA[In MFC program, you&#8217;d better try to avoid using std::string. There is no compelling reason to use it in MFC, and it leads to confusion. There are some standard method to translate among Cstring ,string and char[]. // Suppose CString str; std::string s; char buf[SIZE]; // from CString to std::string s = str; // from [...]]]></description>
			<content:encoded><![CDATA[<p>In MFC program, you&#8217;d better try to avoid using std::string.  There is no compelling reason to use it in MFC, and it leads to confusion.</p>
<p>There are some standard method to translate among Cstring ,string and char[].<br />
<coolcode lang="cpp" linenum="no"><br />
// Suppose<br />
CString str;<br />
std::string s;<br />
char buf[SIZE];</p>
<p>// from CString to std::string<br />
s = str;</p>
<p>// from std::string to CString<br />
str = s.c_str();</p>
<p>// to char[]<br />
_tcscpy(buf, str);<br />
_tcscpy(buf, s.c_str());</p>
<p>// from char[]<br />
str = buf;<br />
s = buf;<br />
</coolcode><br />
Also, beware of unicode. If UNICODE is defined, you should convert between unicode and ansi versions. Better to use TCHAR instead of char and std::basic_string<TCHAR> instead of std::string. </p>

	Tags: <strong><a href="http://www.ucosoft.com/tag/how-to" title="How-to" rel="tag">How-to</a>, <a href="http://www.ucosoft.com/tag/stl" title="STL" rel="tag">STL</a>, <a href="http://www.ucosoft.com/tag/string" title="string" rel="tag">string</a>, <a href="http://www.ucosoft.com/tag/win32mfc" title="Win32/MFC" rel="tag">Win32/MFC</a></strong><br />
]]></content:encoded>
			<wfw:commentRss>http://www.ucosoft.com/how-to-translate-among-cstringstring-and-char-array.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

