<?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[Problem bei Funktion für Stringverarbeitung]]></title><description><![CDATA[<p>Wollte eine Funktion erstellen die aus einer WinApi Editbox den Text ausliest, Text hinzufügt und wenn er eine bestimmt Länge überschreitet den Anfang absäbelt.<br />
Das einzige was jetzt nicht richtig funktioniert sind die Zeilenumbrüche. Ich füg da ein \r\n hinzu wenn ich einen Zeilenumbruch will, aber ich kann grade nicht erkennen in welchen Fällen er nicht dargestellt wird. Ich benutz einen stringstream um jeden Datentyp zu einem String umzuwandeln.<br />
Hier die Funktion:</p>
<pre><code>//nMaxChars ist die maximale Länge des Textes von hWnd
template &lt;class myType&gt;
BOOL AddWindowText(HWND hWnd,myType text,  const int nMaxChars, bool breakLine=1)
{
	stringstream strBuffer;
	char* cstrBuffer=new char[nMaxChars+1]; //GetWindowText fügt eine 0 am Ende hinzu
	int charsRead=0;

	charsRead=GetWindowText(hWnd, cstrBuffer,nMaxChars+1);

	strBuffer&lt;&lt;cstrBuffer;
	strBuffer&lt;&lt;text;
	if(breakLine)
		strBuffer&lt;&lt;&quot;\r\n&quot;;
	string str=strBuffer.str();

	if(str.size()&gt;nMaxChars)
	str=str.substr(str.size()-nMaxChars-1, nMaxChars+1);

	delete [] cstrBuffer;

	return SetWindowText(hWnd, str.c_str());
}
</code></pre>
<p>Also wenn der String nicht gekürzt wird dann wird auch jeder Zeilenumbruch richtig angezeigt, aber irgendwie kommt es vor dass einige einfach verschwinden wenn der Anfang vom Text entfernt werden soll, ich kann grade nichts genaueres erkennen.<br />
Kann da jemand einen Fehler erkennen? Vermutlich eher mehrere Fehler.</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/319630/problem-bei-funktion-für-stringverarbeitung</link><generator>RSS for Node</generator><lastBuildDate>Sat, 25 Jul 2026 03:39:52 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/319630.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 26 Aug 2013 14:55:01 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Problem bei Funktion für Stringverarbeitung on Mon, 26 Aug 2013 14:58:05 GMT]]></title><description><![CDATA[<p>Wollte eine Funktion erstellen die aus einer WinApi Editbox den Text ausliest, Text hinzufügt und wenn er eine bestimmt Länge überschreitet den Anfang absäbelt.<br />
Das einzige was jetzt nicht richtig funktioniert sind die Zeilenumbrüche. Ich füg da ein \r\n hinzu wenn ich einen Zeilenumbruch will, aber ich kann grade nicht erkennen in welchen Fällen er nicht dargestellt wird. Ich benutz einen stringstream um jeden Datentyp zu einem String umzuwandeln.<br />
Hier die Funktion:</p>
<pre><code>//nMaxChars ist die maximale Länge des Textes von hWnd
template &lt;class myType&gt;
BOOL AddWindowText(HWND hWnd,myType text,  const int nMaxChars, bool breakLine=1)
{
	stringstream strBuffer;
	char* cstrBuffer=new char[nMaxChars+1]; //GetWindowText fügt eine 0 am Ende hinzu
	int charsRead=0;

	charsRead=GetWindowText(hWnd, cstrBuffer,nMaxChars+1);

	strBuffer&lt;&lt;cstrBuffer;
	strBuffer&lt;&lt;text;
	if(breakLine)
		strBuffer&lt;&lt;&quot;\r\n&quot;;
	string str=strBuffer.str();

	if(str.size()&gt;nMaxChars)
	str=str.substr(str.size()-nMaxChars-1, nMaxChars+1);

	delete [] cstrBuffer;

	return SetWindowText(hWnd, str.c_str());
}
</code></pre>
<p>Also wenn der String nicht gekürzt wird dann wird auch jeder Zeilenumbruch richtig angezeigt, aber irgendwie kommt es vor dass einige einfach verschwinden wenn der Anfang vom Text entfernt werden soll, ich kann grade nichts genaueres erkennen.<br />
Kann da jemand einen Fehler erkennen? Vermutlich eher mehrere Fehler.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2348624</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2348624</guid><dc:creator><![CDATA[Francis123]]></dc:creator><pubDate>Mon, 26 Aug 2013 14:58:05 GMT</pubDate></item><item><title><![CDATA[Reply to Problem bei Funktion für Stringverarbeitung on Mon, 26 Aug 2013 15:06:16 GMT]]></title><description><![CDATA[<p>Och nö.</p>
<pre><code>template &lt;class myType&gt;
BOOL AddWindowText( HWND hWnd,
                    myType text,
                    std::size_t nMaxChars,
                    bool breakLine = true )
{
    std::string Buffer( nMaxChars + 1 );

    std::size_t charsRead = GetWindowText(hWnd, &amp;Buffer[0], Buffer.length());

    string str = Buffer + text;

    if( breakLine ) // Editiert. Ein if-Statement scheint hier einfach sinnvoller. 
        str += &quot;\r\n&quot;;

    if( str.size() &gt; nMaxChars )
        str.erase( 0, str.size() - nMaxChars );

    return SetWindowText(hWnd, str.c_str());
}
</code></pre>
<p>~(Natürlich ungetestet)~</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2348626</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2348626</guid><dc:creator><![CDATA[Sone]]></dc:creator><pubDate>Mon, 26 Aug 2013 15:06:16 GMT</pubDate></item><item><title><![CDATA[Reply to Problem bei Funktion für Stringverarbeitung on Mon, 26 Aug 2013 15:25:38 GMT]]></title><description><![CDATA[<p>Sone schrieb:</p>
<blockquote>
<pre><code>if( str.size() &gt; nMaxChars )
        str.erase( 0, str.size() - nMaxChars );

    return SetWindowText(hWnd, str.c_str());
}
</code></pre>
</blockquote>
<p>Och nö.</p>
<pre><code class="language-cpp">return SetWindowText(hWnd, str.size()&gt;nMaxChars ? &amp;*str.end() - nMaxChars : str.c_str());
</code></pre>
<p>~(Selbstverständlich natürlich ungetestet)~</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2348639</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2348639</guid><dc:creator><![CDATA[untester]]></dc:creator><pubDate>Mon, 26 Aug 2013 15:25:38 GMT</pubDate></item><item><title><![CDATA[Reply to Problem bei Funktion für Stringverarbeitung on Mon, 26 Aug 2013 15:34:37 GMT]]></title><description><![CDATA[<p>Geht beides nicht wie es soll. Schon weil man nicht einfach zB Ints und Doubles an einen String anhängen kann.<br />
Und ich wüsste von keinem String constructor der nur ein int nimmt.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2348640</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2348640</guid><dc:creator><![CDATA[Francis123]]></dc:creator><pubDate>Mon, 26 Aug 2013 15:34:37 GMT</pubDate></item><item><title><![CDATA[Reply to Problem bei Funktion für Stringverarbeitung on Mon, 26 Aug 2013 15:40:42 GMT]]></title><description><![CDATA[<p>Dafür gibt es dann std::to_string.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2348643</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2348643</guid><dc:creator><![CDATA[Skym0sh0]]></dc:creator><pubDate>Mon, 26 Aug 2013 15:40:42 GMT</pubDate></item><item><title><![CDATA[Reply to Problem bei Funktion für Stringverarbeitung on Mon, 26 Aug 2013 15:48:00 GMT]]></title><description><![CDATA[<p>Von to_string wusste ich nichts, deswegen hab ich den stringstream benutzt.<br />
Jedenfalls scheint es als hätte nur die Zeile</p>
<pre><code>str.erase( 0, str.size() - nMaxChars );
</code></pre>
<p>das Problem mit den Zeilenumbrüchen gelöst, auch wenn ich den Grund nicht erkenne.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2348651</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2348651</guid><dc:creator><![CDATA[Francis123]]></dc:creator><pubDate>Mon, 26 Aug 2013 15:48:00 GMT</pubDate></item><item><title><![CDATA[Reply to Problem bei Funktion für Stringverarbeitung on Mon, 26 Aug 2013 16:35:17 GMT]]></title><description><![CDATA[<p>Folgendes:</p>
<pre><code class="language-cpp">&amp;*str.end() - nMaxChars
</code></pre>
<p>erzeugt UB (str.end() ist nicht dereferenzierbar). MSVC haut einem im Debug-Modus dafür einen assert um die Ohren.</p>
<pre><code class="language-cpp">str.c_str() + str.size() - nMaxChars
</code></pre>
<p>wär jetzt mein Ansatz. Geht sogar in C++03.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2348663</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2348663</guid><dc:creator><![CDATA[seldon]]></dc:creator><pubDate>Mon, 26 Aug 2013 16:35:17 GMT</pubDate></item><item><title><![CDATA[Reply to Problem bei Funktion für Stringverarbeitung on Mon, 26 Aug 2013 17:42:24 GMT]]></title><description><![CDATA[<p>untester schrieb:</p>
<blockquote>
<p>Och nö.</p>
</blockquote>
<p>Autsch, hast Recht, das bearbeiten des Strings ist völlig überflüssig. Da habe ich wieder zu genau hingeschaut....</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2348681</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2348681</guid><dc:creator><![CDATA[Sone]]></dc:creator><pubDate>Mon, 26 Aug 2013 17:42:24 GMT</pubDate></item><item><title><![CDATA[Reply to Problem bei Funktion für Stringverarbeitung on Tue, 27 Aug 2013 07:27:37 GMT]]></title><description><![CDATA[<p>Es geht auch ohne string oder gar stringstream.</p>
<pre><code>//nMaxChars ist die maximale Länge des Textes von hWnd
template &lt;class myType&gt;
BOOL AddWindowText(HWND hWnd,myType text,  const int nMaxChars, bool breakLine=true)
{
    char* buf=new char[nMaxChars+1]; //GetWindowText fügt eine 0 am Ende hinzu

    GetWindowText(hWnd, buf, nMaxChars+1);
    strncat(buf, text, strlen(buf)&lt;nMaxChars?nMaxChars-strlen(buf):0);
    if( breakLine )
      strncat(buf, &quot;\r\n&quot;, strlen(buf)&lt;nMaxChars-1?2:0);

    BOOL r = SetWindowText(hWnd, buf);
    delete [] buf;
    return r;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2348763</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2348763</guid><dc:creator><![CDATA[Wutz]]></dc:creator><pubDate>Tue, 27 Aug 2013 07:27:37 GMT</pubDate></item><item><title><![CDATA[Reply to Problem bei Funktion für Stringverarbeitung on Tue, 27 Aug 2013 07:51:21 GMT]]></title><description><![CDATA[<p>Wutz, was soll der Blödsinn? Wer zum Teufel arbeitet hier mit <code>new</code> / <code>delete</code> ?</p>
<p>Hier würde sich ein Start/End Iteratorenpaar besser machen.<br />
Edit²: Weil unten schon steht, dass er ja irgendwie jeden Typen ausgeben lassen können will, muss man doch per Referenz o.ä. übergeben.</p>
<blockquote>
<p>Ich benutz einen stringstream um jeden Datentyp zu einem String umzuwandeln.</p>
</blockquote>
<p>Edit: Habe ich übersehen... das ist was anderes. Das geht dann tatsächlich nicht ohne Stringstream, wenn diese Datentypen möglicherweise nur den <code>operator&lt;&lt;</code> überladen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2348764</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2348764</guid><dc:creator><![CDATA[Sone]]></dc:creator><pubDate>Tue, 27 Aug 2013 07:51:21 GMT</pubDate></item><item><title><![CDATA[Reply to Problem bei Funktion für Stringverarbeitung on Tue, 27 Aug 2013 07:46:45 GMT]]></title><description><![CDATA[<p>Reg dich ab.<br />
Set/GetWindowText ist eindeutig WinAPI, und die arbeiten ausschließlich mit char/TCHAR.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2348768</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2348768</guid><dc:creator><![CDATA[Wutz]]></dc:creator><pubDate>Tue, 27 Aug 2013 07:46:45 GMT</pubDate></item><item><title><![CDATA[Reply to Problem bei Funktion für Stringverarbeitung on Tue, 27 Aug 2013 07:51:59 GMT]]></title><description><![CDATA[<p>Wutz schrieb:</p>
<blockquote>
<p>Set/GetWindowText ist eindeutig WinAPI, und die arbeiten ausschließlich mit char/TCHAR.</p>
</blockquote>
<p>Ja, aber das geht trotzdem mit C++-Strings. Da braucht man nicht RAII zu vernachlässigen. <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>
<p>Ich werfe mal eine neue Version in den Ring:</p>
<pre><code>template &lt;class myType&gt;
BOOL AddWindowText( HWND hWnd,
                    myType const&amp; text,
                    std::size_t nMaxChars,
                    bool breakLine = true )
{
    std::string Buffer( nMaxChars + 1 );

    GetWindowText(hWnd, &amp;Buffer[0], Buffer.length());

    std::ostringstream stream( Buffer );
    stream &lt;&lt; text;

    if( breakLine )
        stream &lt;&lt; &quot;\r\n&quot;;

    std::string rval = stream.str();
    char const* begin = rval.c_str():

    if( rval.length() &gt; nMaxChars )
		begin += rval.length() - nMaxChars - 1;

    return SetWindowText(hWnd, begin);
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2348770</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2348770</guid><dc:creator><![CDATA[Sone]]></dc:creator><pubDate>Tue, 27 Aug 2013 07:51:59 GMT</pubDate></item><item><title><![CDATA[Reply to Problem bei Funktion für Stringverarbeitung on Wed, 28 Aug 2013 17:14:50 GMT]]></title><description><![CDATA[<p>Ein anderes kleines Problem ist die to_string Funktion. Wieso muss ich ein int zu long double casten beim übergeben und wieso hat to_string bei mir nur 3 varianten die alle kein int nehmen, wie es hier zu sehen ist: <a href="http://www.cplusplus.com/reference/string/to_string/?kw=to_string" rel="nofollow">http://www.cplusplus.com/reference/string/to_string/?kw=to_string</a></p>
<p>Außerdem würde ich gern den &lt;&lt; Operator für HWND überladen, aber es geht nicht.</p>
<pre><code>HWND operator&lt;&lt;(HWND hWnd, const char* text)
{
	AddWindowText(hWnd, text);
	return hWnd;
}
</code></pre>
<p>Da kommt nur die Meldung dass ein Operator der kein Member ist einen Klassen- oder Enumerationstyp erfordert. Geht der Operator also nur als Klassenmember?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2349018</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2349018</guid><dc:creator><![CDATA[Francis123]]></dc:creator><pubDate>Wed, 28 Aug 2013 17:14:50 GMT</pubDate></item><item><title><![CDATA[Reply to Problem bei Funktion für Stringverarbeitung on Thu, 29 Aug 2013 17:53:43 GMT]]></title><description><![CDATA[<p>hat keine ne idee?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2349247</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2349247</guid><dc:creator><![CDATA[Francis123]]></dc:creator><pubDate>Thu, 29 Aug 2013 17:53:43 GMT</pubDate></item><item><title><![CDATA[Reply to Problem bei Funktion für Stringverarbeitung on Thu, 29 Aug 2013 18:14:44 GMT]]></title><description><![CDATA[<p>Wutz schrieb:</p>
<blockquote>
<p>Set/GetWindowText ist eindeutig WinAPI, und die arbeiten ausschließlich mit char/TCHAR.</p>
</blockquote>
<p>Och, ein std::vector&lt;char/TCHAR&gt; tut es auch, vector&lt;...&gt;.data() gibt es schon in VS 2010.</p>
<p>Das Problem: Ist das Window dann owner des Textes?</p>
<blockquote>
<p>Wieso muss ich ein int zu long double casten beim übergeben und wieso hat to_string bei mir nur 3 varianten die alle kein int nehmen,</p>
</blockquote>
<p>1.) Es gibt auch eine Ueberladung fuer (in)signed Long Long.<br />
2.) Du benutzt wahrscheinlich VS 2010.</p>
<blockquote>
<p>Außerdem würde ich gern den &lt;&lt; Operator für HWND überladen, aber es geht nicht.</p>
</blockquote>
<p>1.) Tolle Fehlerbeschreibung<br />
2.) HWND ist wahrscheinlich ein void*, diese ueberladung gibt es wahrscheinlich schon.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2349252</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2349252</guid><dc:creator><![CDATA[knivil]]></dc:creator><pubDate>Thu, 29 Aug 2013 18:14:44 GMT</pubDate></item><item><title><![CDATA[Reply to Problem bei Funktion für Stringverarbeitung on Thu, 29 Aug 2013 18:10:44 GMT]]></title><description><![CDATA[<p>1. to_string() hat Überladungen für fast alle arithmetischen Typen, sieht man auch in deinem Link, es gibt auch eine für int.<br />
2. Operaturüberladungsfunktionen müssen mindestens einen benutzerdefinierten Typen (Klasse, ....) als Argument nehmen (oder zurückgeben?), du kannst keine Version für zwei Pointer schreiben (HWND ist ein Typedef für einen Pointer auf eine struct HWND__ oder mit ähnlichem Namen, weiß ich nicht auswendig).<br />
So eine Operatorüberladung ist auch schwachsinnig und unintuitiv (?).<br />
Falls du es doch machen willst, musst du entweder HWND in eine Klasse kapseln (was du schon allein wegen RAII machen solltest!) oder einen std::string als zweites Argument nehmen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2349253</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2349253</guid><dc:creator><![CDATA[Nathan]]></dc:creator><pubDate>Thu, 29 Aug 2013 18:10:44 GMT</pubDate></item><item><title><![CDATA[Reply to Problem bei Funktion für Stringverarbeitung on Thu, 29 Aug 2013 20:06:58 GMT]]></title><description><![CDATA[<p>Francis123 schrieb:</p>
<blockquote>
<p>Ein anderes kleines Problem ist die to_string Funktion. Wieso muss ich ein int zu long double casten beim übergeben und wieso hat to_string bei mir nur 3 varianten die alle kein int nehmen, wie es hier zu sehen ist: <a href="http://www.cplusplus.com/reference/string/to_string/?kw=to_string" rel="nofollow">http://www.cplusplus.com/reference/string/to_string/?kw=to_string</a></p>
</blockquote>
<p>Das leigt daran, dass vor VS2012 mit to_string nur eben die Standard Floatingpoint Zahlen eingebaut waren. to_string ist eigentlich C++11 und war damals im begrenzten Umfang eine kleine Erweiterung von VS2010 (und ich weis nicht welchen Versionen vorher), mit VS2012 wird to_string dann voll unterstützt.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2349287</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2349287</guid><dc:creator><![CDATA[Skym0sh0]]></dc:creator><pubDate>Thu, 29 Aug 2013 20:06:58 GMT</pubDate></item><item><title><![CDATA[Reply to Problem bei Funktion für Stringverarbeitung on Sun, 01 Sep 2013 08:23:11 GMT]]></title><description><![CDATA[<p>Ist es möglich beim Aufrufen einer Funktion die ein Struct erwartet das Struct direkt zu erzeugen ohne vorher eine Variable zu erstellen und diese dann zu übergeben?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2349569</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2349569</guid><dc:creator><![CDATA[Francis123]]></dc:creator><pubDate>Sun, 01 Sep 2013 08:23:11 GMT</pubDate></item><item><title><![CDATA[Reply to Problem bei Funktion für Stringverarbeitung on Sat, 31 Aug 2013 20:47:36 GMT]]></title><description><![CDATA[<p>Meinst du sowas?</p>
<pre><code>struct foo{};
...
func(foo(a, b, c, d, e, f, g));
</code></pre>
<p>?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2349574</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2349574</guid><dc:creator><![CDATA[Nathan]]></dc:creator><pubDate>Sat, 31 Aug 2013 20:47:36 GMT</pubDate></item><item><title><![CDATA[Reply to Problem bei Funktion für Stringverarbeitung on Sun, 01 Sep 2013 08:26:27 GMT]]></title><description><![CDATA[<p>Ja das meine ich, aber bei mir geht das so nicht weil da nur ein Kopierkonstruktor und ein leerer Konstruktor zur Auswahl stehen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2349602</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2349602</guid><dc:creator><![CDATA[Francis123]]></dc:creator><pubDate>Sun, 01 Sep 2013 08:26:27 GMT</pubDate></item><item><title><![CDATA[Reply to Problem bei Funktion für Stringverarbeitung on Sun, 01 Sep 2013 08:32:09 GMT]]></title><description><![CDATA[<p>Dann schreibste halt einen benutzerdefinierten Konstruktor!<br />
Oder du nutzt Aggregat-Initialisierung:</p>
<pre><code>func({a, b, c, d});
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2349605</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2349605</guid><dc:creator><![CDATA[Nathan]]></dc:creator><pubDate>Sun, 01 Sep 2013 08:32:09 GMT</pubDate></item><item><title><![CDATA[Reply to Problem bei Funktion für Stringverarbeitung on Sun, 01 Sep 2013 11:23:48 GMT]]></title><description><![CDATA[<p>Ich will bei einem vector mit diesem struct die structs mit push_back einfügen.<br />
So wie du das geschrieben hast geht es leider nicht. Da steht dann nur es wurde ein Ausdruck erwartet. Geht wohl nur mit einer eigenen Funktion die den vector pointer und die restlichen Daten nimmt.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2349651</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2349651</guid><dc:creator><![CDATA[Francis123]]></dc:creator><pubDate>Sun, 01 Sep 2013 11:23:48 GMT</pubDate></item><item><title><![CDATA[Reply to Problem bei Funktion für Stringverarbeitung on Sun, 01 Sep 2013 12:37:05 GMT]]></title><description><![CDATA[<p>Wutz schrieb:</p>
<blockquote>
<p>Reg dich ab.<br />
Set/GetWindowText ist eindeutig WinAPI, und die arbeiten ausschließlich mit char/TCHAR.</p>
</blockquote>
<p>Das ist kein Grund, mit <code>new[]</code> / <code>delete[]</code> zu arbeiten. Kannst auch genauso gut</p>
<pre><code class="language-cpp">vector&lt;char&gt; puffer(999);
eine_C_Funktion(&amp;puffer[0],999);
</code></pre>
<p>schreiben. Dann kann es dir gar nicht passieren, <code>delete[]</code> zu &quot;vergessen&quot;. Auch wenn du <code>delete[]</code> dort stehen hast, kann ja zwischendurch irgendwo eine Ausnahme fliegen und dann hättest du ein Speicherleck, weil die Ausführung gar nicht erst zum <code>delete[]</code> kommt.</p>
<p>Ab C++11 ist das auch bei std::string erlaubt, weil garantiert ist, dass die Elemente hintereinander im Speicher stehen. Allerdings muss man sich, wenn man das so in String schreiben lässt, selbst um die Nullterminierung kümmern. Die will man typischerweise nicht mit drin haben und auch den Rest dahinter nicht. Also:</p>
<pre><code class="language-cpp">string s (999);
eine_C_Funktion(s.data(),999); // ab C++11
s.erase(find(s.begin(),s.end(),'\0'),s.end());
</code></pre>
<p>(ungetestet)</p>
<p>Merken: <code>new[]</code> und <code>delete[]</code> brauchen wir so gut wie nie mehr.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2349665</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2349665</guid><dc:creator><![CDATA[krümelkacker]]></dc:creator><pubDate>Sun, 01 Sep 2013 12:37:05 GMT</pubDate></item><item><title><![CDATA[Reply to Problem bei Funktion für Stringverarbeitung on Sun, 01 Sep 2013 13:05:58 GMT]]></title><description><![CDATA[<blockquote>
<p>Merken: new[] und delete[] brauchen wir so gut wie nie mehr.</p>
</blockquote>
<p>so gut? <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="🙂"
    /><br />
Ich meine, wir brauchen seit C++11/14* nicht mal <code>new</code> zu schreiben, vorausgesetzt wir arbeiten brav mit Smart-Pointern.</p>
<blockquote>
<p>Auch wenn du delete[] dort stehen hast, kann ja zwischendurch irgendwo eine Ausnahme fliegen und dann hättest du ein Speicherleck, weil die Ausführung gar nicht erst zum delete[] kommt.</p>
</blockquote>
<p>Wieso erklärst du ihm das? Das weiß er (so hoffe ich) selbst.</p>
<blockquote>
<p>HWND ist wahrscheinlich ein void*, diese ueberladung gibt es wahrscheinlich schon.</p>
</blockquote>
<p>Beides richtig. <code>HWND</code> ist ein <code>HANDLE</code> , was wiederum ein <code>PVOID</code> ist. Und der Ausgabeoperator für <code>void*</code> ist schon überladen (in <code>ostream</code> selbst).</p>
<blockquote>
<p>Die will man typischerweise nicht mit drin haben und auch den Rest dahinter nicht.</p>
</blockquote>
<p>Bei vielen solchen Funktionen ist von vornherein klar, dass '\0' das letzte Zeichen im String ist - daher reicht da meistens auch ein pop_back().<br />
Und wieso benutzt du nicht die <code>find()</code> -Funktion aus <code>std::string</code> ?</p>
<ul>
<li><code>make_unique</code></li>
</ul>
]]></description><link>https://www.c-plusplus.net/forum/post/2349672</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2349672</guid><dc:creator><![CDATA[Sone]]></dc:creator><pubDate>Sun, 01 Sep 2013 13:05:58 GMT</pubDate></item><item><title><![CDATA[Reply to Problem bei Funktion für Stringverarbeitung on Sun, 01 Sep 2013 13:15:28 GMT]]></title><description><![CDATA[<p>Sone schrieb:</p>
<blockquote>
<blockquote>
<p>HWND ist wahrscheinlich ein void*, diese ueberladung gibt es wahrscheinlich schon.</p>
</blockquote>
<p>Beides richtig. <code>HWND</code> ist ein <code>HANDLE</code> , was wiederum ein <code>PVOID</code> ist. Und der Ausgabeoperator für <code>void*</code> ist schon überladen (in <code>ostream</code> selbst).</p>
</blockquote>
<p>Er redet nicht vom Ausgabeoperator, Sone. <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f644.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--face_with_rolling_eyes"
      title=":rolling_eyes:"
      alt="🙄"
    /> <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f609.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--winking_face"
      title=";)"
      alt="😉"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/2349675</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2349675</guid><dc:creator><![CDATA[Nathan]]></dc:creator><pubDate>Sun, 01 Sep 2013 13:15:28 GMT</pubDate></item><item><title><![CDATA[Reply to Problem bei Funktion für Stringverarbeitung on Sun, 01 Sep 2013 13:19:43 GMT]]></title><description><![CDATA[<p>Nathan schrieb:</p>
<blockquote>
<p>Sone schrieb:</p>
<blockquote>
<blockquote>
<p>HWND ist wahrscheinlich ein void*, diese ueberladung gibt es wahrscheinlich schon.</p>
</blockquote>
<p>Beides richtig. <code>HWND</code> ist ein <code>HANDLE</code> , was wiederum ein <code>PVOID</code> ist. Und der Ausgabeoperator für <code>void*</code> ist schon überladen (in <code>ostream</code> selbst).</p>
</blockquote>
<p>Er redet nicht vom Ausgabeoperator, Sone. <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f644.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--face_with_rolling_eyes"
      title=":rolling_eyes:"
      alt="🙄"
    /> <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f609.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--winking_face"
      title=";)"
      alt="😉"
    /></p>
</blockquote>
<p>Ich weiß ja nicht, wie du das siehst, aber wenn ich lese</p>
<p>Knivil schrieb:</p>
<blockquote>
<blockquote>
<p>Außerdem würde ich gern den &lt;&lt; Operator für HWND überladen, aber es geht nicht.</p>
</blockquote>
<p>[...]<br />
2.) HWND ist wahrscheinlich ein void*, diese ueberladung gibt es wahrscheinlich schon.</p>
</blockquote>
<p>Dann folgere ich daraus, dass er sich auf das Zitat bezieht...<br />
Edit: Ah, er will gar nicht den <code>operator&lt;&lt;</code> für <code>ostream</code> überladen... :kopf-&gt;tisch: <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/2349676</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2349676</guid><dc:creator><![CDATA[Sone]]></dc:creator><pubDate>Sun, 01 Sep 2013 13:19:43 GMT</pubDate></item></channel></rss>