<?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[wcout und cout überladbar?]]></title><description><![CDATA[<p>Hola!<br />
Ich glaube, der Code zeigt, was ich vorhabe:</p>
<pre><code class="language-cpp">template&lt;typename T&gt; 
void open ( const T&amp; t )
{
	ifstream in;
	in.open(t.c_str());
	if ( in == NULL )
	{
		if ( typeof(t) == string ) //error C2275: 'std::string': Ungültige Verwendung dieses Typs als Ausdruck
			cout &lt;&lt; &quot;Kann &quot; &lt;&lt; t.c_str() &lt;&lt; &quot; nicht oeffnen!&quot; &lt;&lt; endl;
		if ( typeof(t) == wstring )
			wout &lt;&lt; &quot;Kann &quot; &lt;&lt; t.c_str() &lt;&lt; &quot; nicht oeffnen!&quot; &lt;&lt; endl;
	}
}
</code></pre>
<p>Aufruf:</p>
<pre><code class="language-cpp">string str (&quot;test.txt&quot;);
	wstring wstr(L&quot;test.txt&quot;);
	open(str);
	open(wstr);
</code></pre>
<p>Bloß mein Compiler, der mag das nicht:</p>
<blockquote>
<p>error C2275: 'std::string': Ungültige Verwendung dieses Typs als Ausdruck</p>
</blockquote>
<p>Was tun?</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/245893/wcout-und-cout-überladbar</link><generator>RSS for Node</generator><lastBuildDate>Fri, 18 Sep 2026 12:09:37 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/245893.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 20 Jul 2009 15:41:30 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to wcout und cout überladbar? on Mon, 20 Jul 2009 15:41:30 GMT]]></title><description><![CDATA[<p>Hola!<br />
Ich glaube, der Code zeigt, was ich vorhabe:</p>
<pre><code class="language-cpp">template&lt;typename T&gt; 
void open ( const T&amp; t )
{
	ifstream in;
	in.open(t.c_str());
	if ( in == NULL )
	{
		if ( typeof(t) == string ) //error C2275: 'std::string': Ungültige Verwendung dieses Typs als Ausdruck
			cout &lt;&lt; &quot;Kann &quot; &lt;&lt; t.c_str() &lt;&lt; &quot; nicht oeffnen!&quot; &lt;&lt; endl;
		if ( typeof(t) == wstring )
			wout &lt;&lt; &quot;Kann &quot; &lt;&lt; t.c_str() &lt;&lt; &quot; nicht oeffnen!&quot; &lt;&lt; endl;
	}
}
</code></pre>
<p>Aufruf:</p>
<pre><code class="language-cpp">string str (&quot;test.txt&quot;);
	wstring wstr(L&quot;test.txt&quot;);
	open(str);
	open(wstr);
</code></pre>
<p>Bloß mein Compiler, der mag das nicht:</p>
<blockquote>
<p>error C2275: 'std::string': Ungültige Verwendung dieses Typs als Ausdruck</p>
</blockquote>
<p>Was tun?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1746400</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1746400</guid><dc:creator><![CDATA[convert0r]]></dc:creator><pubDate>Mon, 20 Jul 2009 15:41:30 GMT</pubDate></item><item><title><![CDATA[Reply to wcout und cout überladbar? on Mon, 20 Jul 2009 15:44:41 GMT]]></title><description><![CDATA[<pre><code class="language-cpp">bool isString(string const&amp;)
{
   return true;
}
bool isString(wsrting const&amp;)
{
   return false;
}
...
if(isString(t))
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1746402</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1746402</guid><dc:creator><![CDATA[volkard]]></dc:creator><pubDate>Mon, 20 Jul 2009 15:44:41 GMT</pubDate></item><item><title><![CDATA[Reply to wcout und cout überladbar? on Mon, 20 Jul 2009 16:25:29 GMT]]></title><description><![CDATA[<p>Funzt super, danke!</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1746427</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1746427</guid><dc:creator><![CDATA[convert0r]]></dc:creator><pubDate>Mon, 20 Jul 2009 16:25:29 GMT</pubDate></item><item><title><![CDATA[Reply to wcout und cout überladbar? on Mon, 20 Jul 2009 16:27:34 GMT]]></title><description><![CDATA[<p>Ginge nicht auch:</p>
<pre><code class="language-cpp">if(typeof(t) == typeof(std::string)) {
   // ...
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1746432</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1746432</guid><dc:creator><![CDATA[DStefan]]></dc:creator><pubDate>Mon, 20 Jul 2009 16:27:34 GMT</pubDate></item><item><title><![CDATA[Reply to wcout und cout überladbar? on Mon, 20 Jul 2009 16:30:02 GMT]]></title><description><![CDATA[<p>DStefan schrieb:</p>
<blockquote>
<p>Ginge nicht auch:</p>
<pre><code class="language-cpp">if(typeof(t) == typeof(std::string)) {
   // ...
}
</code></pre>
</blockquote>
<p>nein. es gibt keinen == auf typen.<br />
vielleicht meinst du type_id mit RTTI. das ginge.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1746434</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1746434</guid><dc:creator><![CDATA[volkard]]></dc:creator><pubDate>Mon, 20 Jul 2009 16:30:02 GMT</pubDate></item><item><title><![CDATA[Reply to wcout und cout überladbar? on Mon, 20 Jul 2009 16:41:25 GMT]]></title><description><![CDATA[<p>volkard schrieb:</p>
<blockquote>
<p>DStefan schrieb:</p>
<blockquote>
<p>Ginge nicht auch:</p>
<pre><code class="language-cpp">if(typeof(t) == typeof(std::string)) {
   // ...
}
</code></pre>
</blockquote>
<p>nein. es gibt keinen == auf typen.<br />
vielleicht meinst du type_id mit RTTI. das ginge.</p>
</blockquote>
<p>Nee, ich meinte typeof(), weil ich das nämlich nicht kenne. Und Google hat mir auf die Schnelle auch nicht weiter geholfen. Was ist denn die Rückgabe von typeof()?</p>
<p>Stefan.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1746455</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1746455</guid><dc:creator><![CDATA[DStefan]]></dc:creator><pubDate>Mon, 20 Jul 2009 16:41:25 GMT</pubDate></item><item><title><![CDATA[Reply to wcout und cout überladbar? on Mon, 20 Jul 2009 16:43:51 GMT]]></title><description><![CDATA[<p>DStefan schrieb:</p>
<blockquote>
<p>Nee, ich meinte typeof(), weil ich das nämlich nicht kenne. Und Google hat mir auf die Schnelle auch nicht weiter geholfen. Was ist denn die Rückgabe von typeof()?</p>
</blockquote>
<p>Der Typ selber. Und den kannste auch nur nehmen, wo Typen gehen.<br />
kannst ja nicht if(int==int) schreiben.</p>
<pre><code class="language-cpp">int a=5;//wenn ich diesen typ ändere, ändert der von b sich mit
typeof(a) b=a+a;
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1746457</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1746457</guid><dc:creator><![CDATA[volkard]]></dc:creator><pubDate>Mon, 20 Jul 2009 16:43:51 GMT</pubDate></item><item><title><![CDATA[Reply to wcout und cout überladbar? on Mon, 20 Jul 2009 16:47:42 GMT]]></title><description><![CDATA[<p>Es gibt kein wirkliches <code>typeof</code> . Was du vielleicht meinst, ist <code>decltype</code> vom neuen Standard. Damit kann man an den Typen eines Ausdrucks rankommen. Mit == vergleichen geht trotzdem nicht.</p>
<p>Um zwei Typen auf Gleichheit zu überprüfen, reichen Templates:</p>
<pre><code class="language-cpp">template &lt;typename T, typename U&gt;
struct is_same
{
    static const bool value = false;
};

template &lt;typename T&gt;
struct is_same&lt;T, T&gt;
{
    static const bool value = true;
};
</code></pre>
<p>Anwendung:</p>
<pre><code class="language-cpp">bool is_float_equal_to_int = is_same&lt;float, int&gt;::value;
bool is_float_equal_to_float = is_same&lt;float, float&gt;::value;
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1746460</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1746460</guid><dc:creator><![CDATA[Nexus]]></dc:creator><pubDate>Mon, 20 Jul 2009 16:47:42 GMT</pubDate></item></channel></rss>