<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Unicode Files]]></title><description><![CDATA[<p>Gibt es eine Möglichkeit Ansi und Unicode Files mit C++ Funktionen zu öffnen, einzulesen und zu schliessen? Wie konvertiere ich einen std::wstring nach std::string - mit einem std::ostringstream oder vielleicht boost::lexical_cast?</p>
<p>Anmerkung: Die Unicode Files enthalten nur Ansi-Zeichen!</p>
<p>Gruss<br />
T.</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/281574/unicode-files</link><generator>RSS for Node</generator><lastBuildDate>Sun, 23 Aug 2026 14:58:37 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/281574.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 04 Feb 2011 10:19:14 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Unicode Files on Fri, 04 Feb 2011 10:19:14 GMT]]></title><description><![CDATA[<p>Gibt es eine Möglichkeit Ansi und Unicode Files mit C++ Funktionen zu öffnen, einzulesen und zu schliessen? Wie konvertiere ich einen std::wstring nach std::string - mit einem std::ostringstream oder vielleicht boost::lexical_cast?</p>
<p>Anmerkung: Die Unicode Files enthalten nur Ansi-Zeichen!</p>
<p>Gruss<br />
T.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2016446</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2016446</guid><dc:creator><![CDATA[Tomahawk]]></dc:creator><pubDate>Fri, 04 Feb 2011 10:19:14 GMT</pubDate></item><item><title><![CDATA[Reply to Unicode Files on Fri, 04 Feb 2011 10:54:59 GMT]]></title><description><![CDATA[<p>Hallo,</p>
<p>Ich mache das so</p>
<pre><code class="language-cpp">std::string wstring2string( const std::wstring&amp; src, std::locale loc) {
	size_t size = src.size();
	char* Narrow = new char[size+1];
	std::use_facet&lt;std::ctype&lt;wchar_t&gt; &gt; (loc).narrow(src.c_str(), src.c_str() + size, ' ', Narrow);
	Narrow[size] = '\0';
	std::string res(Narrow);
	delete[] Narrow;
	return res;
}
</code></pre>
<p>Das geht mit Sicherheit eleganter. <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f642.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--slightly_smiling_face"
      title=":)"
      alt="🙂"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/2016454</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2016454</guid><dc:creator><![CDATA[Braunstein]]></dc:creator><pubDate>Fri, 04 Feb 2011 10:54:59 GMT</pubDate></item><item><title><![CDATA[Reply to Unicode Files on Fri, 04 Feb 2011 11:01:31 GMT]]></title><description><![CDATA[<p>Da der Aufruf <code>use_facet&lt;blablabla..</code> werfen kann würde ich für <code>Narrow</code> einen <code>std::vector</code> benutzen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2016458</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2016458</guid><dc:creator><![CDATA[brotbernd]]></dc:creator><pubDate>Fri, 04 Feb 2011 11:01:31 GMT</pubDate></item><item><title><![CDATA[Reply to Unicode Files on Fri, 04 Feb 2011 11:16:49 GMT]]></title><description><![CDATA[<p>Oder auto_ptr/scoped_ptr. vector ist nur unbedingt Pflicht, wenn man die Daten später noch kopieren will. Wobei sich die Frage stellt, ob der Aufwand überhaupt notwendig ist? Wenn Unicode gleich UTF8 ist, ist er völlig überflüssig. Andererseits wirst du Probleme bekommen, wenn sizeof(wchar_t) == 2, aber die Datei UTF32 ist.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2016466</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2016466</guid><dc:creator><![CDATA[hav a break]]></dc:creator><pubDate>Fri, 04 Feb 2011 11:16:49 GMT</pubDate></item><item><title><![CDATA[Reply to Unicode Files on Fri, 04 Feb 2011 12:14:08 GMT]]></title><description><![CDATA[<p>hav a break schrieb:</p>
<blockquote>
<p>Oder auto_ptr/scoped_ptr.</p>
</blockquote>
<p>Die <code>delete</code> und nicht <code>delete[]</code> aufrufen, was hier falsch wäre. Wenn dann boost::scoped_array. Den gibts aber eben nur in boost, nix STL (die den hier wunderbar geeigneten vector hat).</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2016492</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2016492</guid><dc:creator><![CDATA[brotbernd]]></dc:creator><pubDate>Fri, 04 Feb 2011 12:14:08 GMT</pubDate></item><item><title><![CDATA[Reply to Unicode Files on Fri, 04 Feb 2011 12:37:21 GMT]]></title><description><![CDATA[<p>Hast recht, soweit hab ich jetzt nicht mitgedacht. Ich dachte nur an RAII und Pointer freigeben. scoped_ptr hätte ich persönlich aber auch wegen boost hintenan gestellt.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2016499</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2016499</guid><dc:creator><![CDATA[hav a break]]></dc:creator><pubDate>Fri, 04 Feb 2011 12:37:21 GMT</pubDate></item><item><title><![CDATA[Reply to Unicode Files on Fri, 04 Feb 2011 14:57:58 GMT]]></title><description><![CDATA[<p>Ok,</p>
<pre><code class="language-cpp">std::string wstring2string( const std::wstring&amp; src, std::locale loc) {
    size_t size = src.size();
    std:vector&lt;char&gt; Narrow(size);
    std::use_facet&lt;std::ctype&lt;wchar_t&gt; &gt; (loc).narrow(src.c_str(), src.c_str() + size, ' ', &amp;(Narrow[0]); // hier evtl. auch Narrow.begin()?
    return std::string(Narrow.begin(), Narrow.end());
}
</code></pre>
<p>So besser?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2016559</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2016559</guid><dc:creator><![CDATA[Braunstein]]></dc:creator><pubDate>Fri, 04 Feb 2011 14:57:58 GMT</pubDate></item></channel></rss>