<?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[Time, Speicherverwaltung in C++]]></title><description><![CDATA[<p>Hallo Leute,</p>
<p>also ich habe folgendes Problem:<br />
ich hole mir die Systemzeit, will mir daraus meinen Namen generieren.<br />
So die printf-anzeife passt, sieht gut aus. Sobald ich aber die strings zusammensetze kommt nur blödsinn raus <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f615.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--confused_face"
      title=":confused:"
      alt="😕"
    /> . Warum?<br />
Hier der einfache Code:<br />
[cpp]</p>
<pre><code>#include &lt;iostream&gt;
#include &lt;time.h&gt;
#include &lt;windows.h&gt;
#include &lt;winsock.h&gt;
#include &lt;winsock2.h&gt;

int main()
{

		char* Name=new char[256];
		char year[4];
		char month[4];
		char Stunde[4];
		char minute[4];
		char date[2];
		int i;
		// char Name[20];
		SYSTEMTIME systime;  

		GetLocalTime(&amp;systime); 

		itoa(systime.wMinute,minute,10);
		itoa(systime.wHour,Stunde,10);
		itoa(systime.wMonth,month,10);
		itoa(systime.wYear,year,10); 
		printf(&quot;%s %s %s %s\n&quot;, Stunde, minute, year, month);
		for(i=0;i&lt;2;i++)
			date[i]=year[i+2];

		Name=date;
		//strcat(Name,&quot;.&quot;);
		//strcat(Name,minute);
		//strcat(Name,minute); 

		printf(&quot;%s\n&quot;, Name);
		return 1;
}
</code></pre>
<p>Danke für eure Hilfe<br />
Tentone</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/219133/time-speicherverwaltung-in-c</link><generator>RSS for Node</generator><lastBuildDate>Thu, 08 Oct 2026 09:34:56 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/219133.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 30 Jul 2008 09:00:40 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Time, Speicherverwaltung in C++ on Wed, 30 Jul 2008 09:00:40 GMT]]></title><description><![CDATA[<p>Hallo Leute,</p>
<p>also ich habe folgendes Problem:<br />
ich hole mir die Systemzeit, will mir daraus meinen Namen generieren.<br />
So die printf-anzeife passt, sieht gut aus. Sobald ich aber die strings zusammensetze kommt nur blödsinn raus <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f615.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--confused_face"
      title=":confused:"
      alt="😕"
    /> . Warum?<br />
Hier der einfache Code:<br />
[cpp]</p>
<pre><code>#include &lt;iostream&gt;
#include &lt;time.h&gt;
#include &lt;windows.h&gt;
#include &lt;winsock.h&gt;
#include &lt;winsock2.h&gt;

int main()
{

		char* Name=new char[256];
		char year[4];
		char month[4];
		char Stunde[4];
		char minute[4];
		char date[2];
		int i;
		// char Name[20];
		SYSTEMTIME systime;  

		GetLocalTime(&amp;systime); 

		itoa(systime.wMinute,minute,10);
		itoa(systime.wHour,Stunde,10);
		itoa(systime.wMonth,month,10);
		itoa(systime.wYear,year,10); 
		printf(&quot;%s %s %s %s\n&quot;, Stunde, minute, year, month);
		for(i=0;i&lt;2;i++)
			date[i]=year[i+2];

		Name=date;
		//strcat(Name,&quot;.&quot;);
		//strcat(Name,minute);
		//strcat(Name,minute); 

		printf(&quot;%s\n&quot;, Name);
		return 1;
}
</code></pre>
<p>Danke für eure Hilfe<br />
Tentone</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1556179</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1556179</guid><dc:creator><![CDATA[Tentone]]></dc:creator><pubDate>Wed, 30 Jul 2008 09:00:40 GMT</pubDate></item><item><title><![CDATA[Reply to Time, Speicherverwaltung in C++ on Wed, 30 Jul 2008 09:05:46 GMT]]></title><description><![CDATA[<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;time.h&gt;
#include &lt;windows.h&gt;
#include &lt;winsock.h&gt;
#include &lt;winsock2.h&gt;

int main()
{

		char* Name=new char[256]; // warum nicht std::string?
		char year[4];
		char month[4];
		char Stunde[4];
		char minute[4];
		char date[2];
		int i;
		// char Name[20];
		SYSTEMTIME systime;  

		GetLocalTime(&amp;systime); 

		itoa(systime.wMinute,minute,10);
		itoa(systime.wHour,Stunde,10);
		itoa(systime.wMonth,month,10);
		itoa(systime.wYear,year,10); 
		printf(&quot;%s %s %s %s\n&quot;, Stunde, minute, year, month);
		for(i=0;i&lt;2;i++)
			date[i]=year[i+2];

		Name=date; // jetzt zeigt Name auf date, also ein char[2].
		//strcat(Name,&quot;.&quot;); // kann gar nicht mehr funzen, siehe unten
		//strcat(Name,minute);
		//strcat(Name,minute); 

		printf(&quot;%s\n&quot;, Name);
		return 1;
}
</code></pre>
<p>Bei deinem ersten strcat zeigt Name schon nicht mehr auf die reservierten 256 byte, sondern auf die 2 byte von date. Und diese sind nicht einmal 0-terminiert, weswegen das Anhängen von weiteren Zeichen mit strcat eh nicht funktioniert. Nimm lieber std::string, lies dich da ein.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1556186</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1556186</guid><dc:creator><![CDATA[Fellhuhn]]></dc:creator><pubDate>Wed, 30 Jul 2008 09:05:46 GMT</pubDate></item><item><title><![CDATA[Reply to Time, Speicherverwaltung in C++ on Wed, 30 Jul 2008 09:12:55 GMT]]></title><description><![CDATA[<p>Falls du nicht wie es Fellhuhn vorgeschlagen hat std::string verwenden willst, kannst du auch noch sprintf verwenden...</p>
<pre><code class="language-cpp">sprintf(Name, &quot;%s.%s&quot;, date, year); // Verwendung wie printf
</code></pre>
<p>Zur Umwandlung von Zahlen nach Strings und zurück gibts übrigens auch noch nen guten <a href="http://www.c-plusplus.net/forum/viewtopic-var-t-is-39488.html" rel="nofollow">FAQ Beitrag</a></p>
<p>Gruß<br />
Tobi</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1556192</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1556192</guid><dc:creator><![CDATA[Tobias Gerg]]></dc:creator><pubDate>Wed, 30 Jul 2008 09:12:55 GMT</pubDate></item><item><title><![CDATA[Reply to Time, Speicherverwaltung in C++ on Wed, 30 Jul 2008 09:25:16 GMT]]></title><description><![CDATA[<p>Hallo nochmal,</p>
<p>habe den Code jetzt mit ostringstream umgeschrieben.<br />
Bekomme aber jetzt folgende Fehlermeldung:<br />
aggregate 'std::ostringstream year' has incomplete type and connot be defined</p>
<p>Gruß<br />
Tentone</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1556202</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1556202</guid><dc:creator><![CDATA[Tentone]]></dc:creator><pubDate>Wed, 30 Jul 2008 09:25:16 GMT</pubDate></item><item><title><![CDATA[Reply to Time, Speicherverwaltung in C++ on Wed, 30 Jul 2008 09:26:40 GMT]]></title><description><![CDATA[<p>Der sprintf-Ansatz funktioniert ohne Limitierung aber auch nicht, da date nicht 0-terminiert ist und sprintf so nicht weiß, wann date endet. Und vorher wird sowieso über die Speicherbereiche geschrieben bei itoa. Immer die terminierende 0 mit einberechnen bei der Länge.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1556205</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1556205</guid><dc:creator><![CDATA[Fellhuhn]]></dc:creator><pubDate>Wed, 30 Jul 2008 09:26:40 GMT</pubDate></item><item><title><![CDATA[Reply to Time, Speicherverwaltung in C++ on Wed, 30 Jul 2008 09:40:39 GMT]]></title><description><![CDATA[<p>Fellhuhn schrieb:</p>
<blockquote>
<p>Der sprintf-Ansatz funktioniert ohne Limitierung aber auch nicht, da date nicht 0-terminiert ist und sprintf so nicht weiß, wann date endet. Und vorher wird sowieso über die Speicherbereiche geschrieben bei itoa. Immer die terminierende 0 mit einberechnen bei der Länge.</p>
</blockquote>
<p>Da hast du natürlich völlig recht...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1556219</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1556219</guid><dc:creator><![CDATA[Tobias Gerg]]></dc:creator><pubDate>Wed, 30 Jul 2008 09:40:39 GMT</pubDate></item><item><title><![CDATA[Reply to Time, Speicherverwaltung in C++ on Thu, 31 Jul 2008 11:00:46 GMT]]></title><description><![CDATA[<p>Hallo,</p>
<p>Tentone schrieb:</p>
<blockquote>
<p>Hallo nochmal,</p>
<p>habe den Code jetzt mit ostringstream umgeschrieben.<br />
Bekomme aber jetzt folgende Fehlermeldung:<br />
aggregate 'std::ostringstream year' has incomplete type and connot be defined</p>
<p>Gruß<br />
Tentone</p>
</blockquote>
<p>&lt;sstream&gt; includieren, nicht &lt;strstream&gt;</p>
<p>MfG,</p>
<p>Probe-Nutzer</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1556954</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1556954</guid><dc:creator><![CDATA[Probe-Nutzer]]></dc:creator><pubDate>Thu, 31 Jul 2008 11:00:46 GMT</pubDate></item><item><title><![CDATA[Reply to Time, Speicherverwaltung in C++ on Thu, 31 Jul 2008 11:12:42 GMT]]></title><description><![CDATA[<p>mal ganz ehrlich: der erste Quellcode den du gepostet hast, hat rein garnichts mit C++ zu tun, mal abgesehen vom allerersten include - und das ist überflüssig weil du keine iostreams benutzt. Binde stattdessen stdio.h ein und es ist einfach nur ein C-Programm.<br />
Also bist du entweder im falschen Forum gelandet oder du solltest dich dringend mal mit den C++ iostreams, stringstreams, strings usw. auseinandersetzen, je nachdem ob du denn nu auf C oder C++ aus bist.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1556962</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1556962</guid><dc:creator><![CDATA[pumuckl]]></dc:creator><pubDate>Thu, 31 Jul 2008 11:12:42 GMT</pubDate></item></channel></rss>