<?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[stream.read Problem]]></title><description><![CDATA[<p>Hi, ich möchte eine Datei einlesen. Dazu habe ich folgenden Code:</p>
<pre><code>std::vector&lt;wchar_t&gt; data;
    std::basic_ifstream&lt;wchar_t&gt; stream(fileName, std::ios::binary);
	stream.unsetf(std::ios::skipws);
	stream.seekg(0, std::ios::end);
	int size = stream.tellg();
	stream.seekg(0, std::ios::beg);
	data.resize(size + 1);
	stream.read(&amp;data.front(), static_cast&lt;std::streamsize&gt;(size));
	stream.close();
	data[size] = 0;
	data.push_back(L'\0');
</code></pre>
<p>Das funktioniert. Jetzt möchte ich aber anstatt dem wchar_t meine eigenen Char-Klasse verwenden:</p>
<pre><code>std::vector&lt;Char&gt; data;
    std::basic_ifstream&lt;Char&gt; stream(fileName, std::ios::binary);
	stream.unsetf(std::ios::skipws);
	stream.seekg(0, std::ios::end);
	int size = stream.tellg();
	stream.seekg(0, std::ios::beg);
	data.resize(size + 1);
	stream.read(&amp;data.front(), static_cast&lt;std::streamsize&gt;(size));
	stream.close();
	data[size] = 0;
	data.push_back(L'\0');
</code></pre>
<p>was zur Folge hat, dass das Programm in der Zeile mit dem &quot;stream.read&quot; abstürzt. Die Char Klasse sieht so aus:</p>
<pre><code>class Char
{
public:
	Char();
	Char(const wchar_t&amp; value);
	operator wchar_t() const;
};
</code></pre>
<p>Woran kann das liegen?</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/286115/stream-read-problem</link><generator>RSS for Node</generator><lastBuildDate>Fri, 21 Aug 2026 01:41:59 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/286115.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 03 May 2011 19:07:58 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to stream.read Problem on Tue, 03 May 2011 19:07:58 GMT]]></title><description><![CDATA[<p>Hi, ich möchte eine Datei einlesen. Dazu habe ich folgenden Code:</p>
<pre><code>std::vector&lt;wchar_t&gt; data;
    std::basic_ifstream&lt;wchar_t&gt; stream(fileName, std::ios::binary);
	stream.unsetf(std::ios::skipws);
	stream.seekg(0, std::ios::end);
	int size = stream.tellg();
	stream.seekg(0, std::ios::beg);
	data.resize(size + 1);
	stream.read(&amp;data.front(), static_cast&lt;std::streamsize&gt;(size));
	stream.close();
	data[size] = 0;
	data.push_back(L'\0');
</code></pre>
<p>Das funktioniert. Jetzt möchte ich aber anstatt dem wchar_t meine eigenen Char-Klasse verwenden:</p>
<pre><code>std::vector&lt;Char&gt; data;
    std::basic_ifstream&lt;Char&gt; stream(fileName, std::ios::binary);
	stream.unsetf(std::ios::skipws);
	stream.seekg(0, std::ios::end);
	int size = stream.tellg();
	stream.seekg(0, std::ios::beg);
	data.resize(size + 1);
	stream.read(&amp;data.front(), static_cast&lt;std::streamsize&gt;(size));
	stream.close();
	data[size] = 0;
	data.push_back(L'\0');
</code></pre>
<p>was zur Folge hat, dass das Programm in der Zeile mit dem &quot;stream.read&quot; abstürzt. Die Char Klasse sieht so aus:</p>
<pre><code>class Char
{
public:
	Char();
	Char(const wchar_t&amp; value);
	operator wchar_t() const;
};
</code></pre>
<p>Woran kann das liegen?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2058050</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2058050</guid><dc:creator><![CDATA[Streamer]]></dc:creator><pubDate>Tue, 03 May 2011 19:07:58 GMT</pubDate></item><item><title><![CDATA[Reply to stream.read Problem on Tue, 03 May 2011 19:24:46 GMT]]></title><description><![CDATA[<p>Dein Char hat überhaupt keinen Inhalt, nur Funktionen. Wo soll da etwas hingeschrieben werden?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2058064</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2058064</guid><dc:creator><![CDATA[SeppJ]]></dc:creator><pubDate>Tue, 03 May 2011 19:24:46 GMT</pubDate></item><item><title><![CDATA[Reply to stream.read Problem on Tue, 03 May 2011 19:42:24 GMT]]></title><description><![CDATA[<p>Doch, habe ich nur vergessen mit rüber zu kopieren:</p>
<pre><code>protected:
	wchar_t value;
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2058085</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2058085</guid><dc:creator><![CDATA[Streamer]]></dc:creator><pubDate>Tue, 03 May 2011 19:42:24 GMT</pubDate></item><item><title><![CDATA[Reply to stream.read Problem on Tue, 03 May 2011 19:55:16 GMT]]></title><description><![CDATA[<p>Dann verheimliche uns bitte nicht alles. Wenn ich alles so ergänze wie ich es für richtig halte und so dass es compiliert, dann funktioniert es bei mir tadellos.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2058094</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2058094</guid><dc:creator><![CDATA[SeppJ]]></dc:creator><pubDate>Tue, 03 May 2011 19:55:16 GMT</pubDate></item><item><title><![CDATA[Reply to stream.read Problem on Tue, 03 May 2011 21:55:20 GMT]]></title><description><![CDATA[<p>Ich will nichts verheimlichen, nur wollte ich das ganze übersichtlich halten.</p>
<p>Der Rest der Char Klasse schaut so aus:</p>
<pre><code>Char::Char() :
	value(L'')
{
}

Char::Char(const wchar_t&amp; value) :
	value(value)
{
}

Char::operator wchar_t() const
{
	return value;
}
</code></pre>
<p>Also ganz trivial.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2058148</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2058148</guid><dc:creator><![CDATA[Streamer]]></dc:creator><pubDate>Tue, 03 May 2011 21:55:20 GMT</pubDate></item></channel></rss>