<?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 mit Funktions Rückgabewert]]></title><description><![CDATA[<p>Hallo wie kann ich den User Name in mein Hauptprogramm bekommen ?</p>
<p>In der Funktion kann ich mir den Namen ja ausgeben lassen aber ich möchte den gerne im Hauptprogramm erst ausgeben.</p>
<p>Hier mein Ansatz:</p>
<p>Aber da bekomme ich nur irgendwelche Zahlen ausgeben.</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;windows&gt;
#include &lt;sstream&gt;
using namespace std;

int user ();

int main(int argc, char* argv[])
{

int var;
string user_name;

var = user();

stringstream int_to_str;

        int_to_str &lt;&lt; var;
        int_to_str &gt;&gt; user_name;

cout&lt;&lt; user_name;

system(&quot;PAUSE&quot;);

return 0;
}

int user()
{

char name[100];
int ret;

stringstream str_to_int;
string str_ret;

DWORD length = sizeof(name);
GetUserName( name,  &amp;length );

        str_ret = name;

        str_to_int &lt;&lt; str_ret;
        str_to_int &gt;&gt; ret;

return ret;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/topic/254151/problem-mit-funktions-rückgabewert</link><generator>RSS for Node</generator><lastBuildDate>Sun, 13 Sep 2026 02:00:36 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/254151.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 12 Nov 2009 11:47:50 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Problem mit Funktions Rückgabewert on Thu, 12 Nov 2009 11:47:50 GMT]]></title><description><![CDATA[<p>Hallo wie kann ich den User Name in mein Hauptprogramm bekommen ?</p>
<p>In der Funktion kann ich mir den Namen ja ausgeben lassen aber ich möchte den gerne im Hauptprogramm erst ausgeben.</p>
<p>Hier mein Ansatz:</p>
<p>Aber da bekomme ich nur irgendwelche Zahlen ausgeben.</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;windows&gt;
#include &lt;sstream&gt;
using namespace std;

int user ();

int main(int argc, char* argv[])
{

int var;
string user_name;

var = user();

stringstream int_to_str;

        int_to_str &lt;&lt; var;
        int_to_str &gt;&gt; user_name;

cout&lt;&lt; user_name;

system(&quot;PAUSE&quot;);

return 0;
}

int user()
{

char name[100];
int ret;

stringstream str_to_int;
string str_ret;

DWORD length = sizeof(name);
GetUserName( name,  &amp;length );

        str_ret = name;

        str_to_int &lt;&lt; str_ret;
        str_to_int &gt;&gt; ret;

return ret;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1806924</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1806924</guid><dc:creator><![CDATA[str_int]]></dc:creator><pubDate>Thu, 12 Nov 2009 11:47:50 GMT</pubDate></item><item><title><![CDATA[Reply to Problem mit Funktions Rückgabewert on Thu, 12 Nov 2009 11:54:39 GMT]]></title><description><![CDATA[<p>Wieso konvertierst du in der Funktion mit Stringstreams herum? Gib einfach nen <code>std::string</code> zurück.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1806926</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1806926</guid><dc:creator><![CDATA[Ad aCTa]]></dc:creator><pubDate>Thu, 12 Nov 2009 11:54:39 GMT</pubDate></item><item><title><![CDATA[Reply to Problem mit Funktions Rückgabewert on Thu, 12 Nov 2009 12:04:20 GMT]]></title><description><![CDATA[<p>Weil man einen string nicht einfach so zurück geben kann.</p>
<pre><code class="language-cpp">int user()
{

char name[100];

string str_name;

DWORD length = sizeof(name);
GetUserName( name,  &amp;length );

str_name = name;

return str_name;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1806936</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1806936</guid><dc:creator><![CDATA[str_int]]></dc:creator><pubDate>Thu, 12 Nov 2009 12:04:20 GMT</pubDate></item><item><title><![CDATA[Reply to Problem mit Funktions Rückgabewert on Thu, 12 Nov 2009 12:07:52 GMT]]></title><description><![CDATA[<p>??<br />
Wie wäre es, wenn du den Rückgabetypen anpasst?</p>
<pre><code class="language-cpp">string user()
{

char name[100];

string str_name;

DWORD length = sizeof(name);
GetUserName( name,  &amp;length );

str_name = name;

return str_name;
}
</code></pre>
<p>Ich würde sagen, dass es noch besser geht, aber ohne zu wissen, wie GetUserName arbeitet kann ich keinen Vorschlag machen.<br />
Aber das gezeigte sollte ohne Probleme funktionieren..</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1806940</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1806940</guid><dc:creator><![CDATA[drakon]]></dc:creator><pubDate>Thu, 12 Nov 2009 12:07:52 GMT</pubDate></item><item><title><![CDATA[Reply to Problem mit Funktions Rückgabewert on Thu, 12 Nov 2009 12:10:19 GMT]]></title><description><![CDATA[<p>Ja so gehts ty.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1806944</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1806944</guid><dc:creator><![CDATA[str_int]]></dc:creator><pubDate>Thu, 12 Nov 2009 12:10:19 GMT</pubDate></item><item><title><![CDATA[Reply to Problem mit Funktions Rückgabewert on Thu, 12 Nov 2009 12:15:23 GMT]]></title><description><![CDATA[<blockquote>
<p>&gt; Ich würde sagen, dass es noch besser geht, aber ohne zu wissen, wie GetUserName arbeitet kann ich keinen Vorschlag machen.</p>
</blockquote>
<p>Musst du auch nicht wissen. Aber da es eh eine Value-Rückgabe ist, kann man sich die Bytes RAM für den string in der Funktion sparen.</p>
<pre><code class="language-cpp">string user() {
   char name[100];
   DWORD length = sizeof(name);
   GetUserName(name,  &amp;length);
   return name;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1806951</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1806951</guid><dc:creator><![CDATA[Ad aCTa]]></dc:creator><pubDate>Thu, 12 Nov 2009 12:15:23 GMT</pubDate></item><item><title><![CDATA[Reply to Problem mit Funktions Rückgabewert on Thu, 12 Nov 2009 18:05:20 GMT]]></title><description><![CDATA[<p>Ad aCTa schrieb:</p>
<blockquote>
<p>Musst du auch nicht wissen. Aber da es eh eine Value-Rückgabe ist, kann man sich die Bytes RAM für den string in der Funktion sparen.</p>
</blockquote>
<p>Wenn man auf Performance aus ist, kann man auch gleich das Array ausserhalb der Funktion deklarieren und so eine <code>std::string</code> -Konstruktion sparen.</p>
<p>Wie sehr sich das lohnt, ist wieder eine andere Frage.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1807158</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1807158</guid><dc:creator><![CDATA[Nexus]]></dc:creator><pubDate>Thu, 12 Nov 2009 18:05:20 GMT</pubDate></item><item><title><![CDATA[Reply to Problem mit Funktions Rückgabewert on Thu, 12 Nov 2009 19:55:00 GMT]]></title><description><![CDATA[<p>Ad aCTa schrieb:</p>
<blockquote>
<blockquote>
<p>&gt; Ich würde sagen, dass es noch besser geht, aber ohne zu wissen, wie GetUserName arbeitet kann ich keinen Vorschlag machen.</p>
</blockquote>
</blockquote>
<p>Jop, aber ich meinte eigentlich eher das hier:</p>
<pre><code class="language-cpp">char name[100];
</code></pre>
<p>Warum sollte man sich da auf 100 Zeichen beschränken? - Ich denke mal, dass man GetUserName entsprechend anpassen könnte, dass es da keine solche sinnlose Beschränkung gibt. (Mir ist klar, dass ein Name kaum über 100 Zeichen hat, aber man könnte das ja über einen Parameter steuern, wenn es denn sein muss).</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1807223</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1807223</guid><dc:creator><![CDATA[drakon]]></dc:creator><pubDate>Thu, 12 Nov 2009 19:55:00 GMT</pubDate></item><item><title><![CDATA[Reply to Problem mit Funktions Rückgabewert on Thu, 12 Nov 2009 21:11:49 GMT]]></title><description><![CDATA[<p>&quot;Warum sollte man sich da auf 100 Zeichen beschränken?&quot;</p>
<p>Jopp - imho gibts da auch ne WinAPI fkt., die die max. länge zurückgibt (imho aber wiederrum nur die theoretisch max. und nicht die praktische max.-länge). wenn man die nicht verwenden will, hat man allerdings eh immer nen ausdruck, der zur compilezeit bekannt ist - es sei denn, man will den nutzer davor fragen, wie lang sein nutzername wird... aber dann könnte man sich wohl auch den aufruf an sich sparen und gleich nach dem namen fragen ;o)</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1807254</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1807254</guid><dc:creator><![CDATA[unskilled]]></dc:creator><pubDate>Thu, 12 Nov 2009 21:11:49 GMT</pubDate></item><item><title><![CDATA[Reply to Problem mit Funktions Rückgabewert on Fri, 13 Nov 2009 13:28:06 GMT]]></title><description><![CDATA[<p>Ausschnitt aus der WinAPI-Hilfe:</p>
<blockquote>
<p>GetUserName<br />
...<br />
If this buffer is not large enough to contain the entire user name, the function fails.</p>
</blockquote>
<p>d.h. um den kompletten Namen sicher zu erhalten müßte man dynamisch die Funktion mit einem immer größeren Buffer aufrufen (andererseits müßten 100 Zeichen schon reichen).</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1807523</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1807523</guid><dc:creator><![CDATA[Th69]]></dc:creator><pubDate>Fri, 13 Nov 2009 13:28:06 GMT</pubDate></item><item><title><![CDATA[Reply to Problem mit Funktions Rückgabewert on Fri, 13 Nov 2009 15:03:54 GMT]]></title><description><![CDATA[<p>ok, die fkt gibts doch nicht, von der ich dachte, dass es sie geben würde ;o)<br />
hier kann aber ne konstante genommen werden:<br />
<code>32767</code></p>
<p>bb</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1807574</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1807574</guid><dc:creator><![CDATA[unskilled]]></dc:creator><pubDate>Fri, 13 Nov 2009 15:03:54 GMT</pubDate></item></channel></rss>