<?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>Mon, 19 Jul 2010 04:51:18 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</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 />

	<ul class="st-related-posts">
	<li><a href="http://www.ucosoft.com/ucogrid-a-great-grid-control-of-mfc.html" title="ucoGrid, a great grid control of MFC (November 26, 2006)">ucoGrid, a great grid control of MFC</a> (18)</li>
	<li><a href="http://www.ucosoft.com/stack-vs-heap.html" title="Stack vs. Heap (January 12, 2008)">Stack vs. Heap</a> (1)</li>
	<li><a href="http://www.ucosoft.com/sscanf-with-cstring.html" title="sscanf with CString (March 20, 2007)">sscanf with CString</a> (3)</li>
	<li><a href="http://www.ucosoft.com/solution-crash-in-release-build-with-self-defined-message.html" title="Solution: Crash in Release build with self-defined message (November 28, 2006)">Solution: Crash in Release build with self-defined message</a> (0)</li>
	<li><a href="http://www.ucosoft.com/simple-code-to-create-an-emf-or-bitmap-file-from-existed-draw-code.html" title="Simple code to create an EMF or Bitmap file from existed draw code (December 16, 2006)">Simple code to create an EMF or Bitmap file from existed draw code</a> (0)</li>
	<li><a href="http://www.ucosoft.com/simple-cedit-validation.html" title="Simple CEdit Validation (June 27, 2007)">Simple CEdit Validation</a> (0)</li>
	<li><a href="http://www.ucosoft.com/set-the-head-backgroud-color-of-cpropertypage.html" title="Set the head backgroud color of CPropertyPage (October 18, 2007)">Set the head backgroud color of CPropertyPage</a> (0)</li>
	<li><a href="http://www.ucosoft.com/moving-selection-of-clistctrl.html" title="Moving selection of CListCtrl (December 3, 2006)">Moving selection of CListCtrl</a> (0)</li>
	<li><a href="http://www.ucosoft.com/how-to-subclass-ctreectrl-in-ctreeview.html" title="How to subclass CTreeCtrl in CTreeView? (October 25, 2007)">How to subclass CTreeCtrl in CTreeView?</a> (0)</li>
	<li><a href="http://www.ucosoft.com/how-to-sort-items-of-clistctrl-or-clistview.html" title="How to sort items of CListCtrl or CListView? (October 22, 2007)">How to sort items of CListCtrl or CListView?</a> (0)</li>
</ul>

]]></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>
