<?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[Kurze Design Frage]]></title><description><![CDATA[<p>Hallo, die Funktion InternetConnect nimmt nur C Strings an wie es scheint.</p>
<p>Daher meine Frage was ist besser wenn ich es so mache:</p>
<pre><code class="language-cpp">int MyClass :: VerbindeZuServer(std::string srvname, std::string username, std::string password )
{
HINTERNET net;

net = InternetOpen(0, INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 

	net = InternetConnect( hinternet, srvname.c_str() , INTERNET_DEFAULT_FTP_PORT, username.c_str(), password.c_str(),
					INTERNET_SERVICE_FTP, INTERNET_FLAG_PASSIVE, NULL );

return 0;
}
</code></pre>
<p>Oder wenn ich das so mache:</p>
<pre><code class="language-cpp">int MyClass :: VerbindeZuServer(char* srvname, char* username, char* password )
{
HINTERNET net;

net = InternetOpen(0, INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 

	net = InternetConnect( hinternet, srvname , INTERNET_DEFAULT_FTP_PORT, username, password,
					INTERNET_SERVICE_FTP, INTERNET_FLAG_PASSIVE, NULL );

return 0;
}
</code></pre>
<p>Mit .c_str(); mache ich ja aus einem C++ String einen C String aber macht das Sinn?</p>
<p>Oder sollte ich da lieber direkt die C Strings benutzen obwohl ich ja eigentlich in C++ Programmiere.</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/300110/kurze-design-frage</link><generator>RSS for Node</generator><lastBuildDate>Wed, 12 Aug 2026 22:51:38 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/300110.rss" rel="self" type="application/rss+xml"/><pubDate>Sat, 25 Feb 2012 15:41:25 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Kurze Design Frage on Sat, 25 Feb 2012 15:41:25 GMT]]></title><description><![CDATA[<p>Hallo, die Funktion InternetConnect nimmt nur C Strings an wie es scheint.</p>
<p>Daher meine Frage was ist besser wenn ich es so mache:</p>
<pre><code class="language-cpp">int MyClass :: VerbindeZuServer(std::string srvname, std::string username, std::string password )
{
HINTERNET net;

net = InternetOpen(0, INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 

	net = InternetConnect( hinternet, srvname.c_str() , INTERNET_DEFAULT_FTP_PORT, username.c_str(), password.c_str(),
					INTERNET_SERVICE_FTP, INTERNET_FLAG_PASSIVE, NULL );

return 0;
}
</code></pre>
<p>Oder wenn ich das so mache:</p>
<pre><code class="language-cpp">int MyClass :: VerbindeZuServer(char* srvname, char* username, char* password )
{
HINTERNET net;

net = InternetOpen(0, INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 

	net = InternetConnect( hinternet, srvname , INTERNET_DEFAULT_FTP_PORT, username, password,
					INTERNET_SERVICE_FTP, INTERNET_FLAG_PASSIVE, NULL );

return 0;
}
</code></pre>
<p>Mit .c_str(); mache ich ja aus einem C++ String einen C String aber macht das Sinn?</p>
<p>Oder sollte ich da lieber direkt die C Strings benutzen obwohl ich ja eigentlich in C++ Programmiere.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2185629</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2185629</guid><dc:creator><![CDATA[CptQuak]]></dc:creator><pubDate>Sat, 25 Feb 2012 15:41:25 GMT</pubDate></item><item><title><![CDATA[Reply to Kurze Design Frage on Sat, 25 Feb 2012 15:51:48 GMT]]></title><description><![CDATA[<p>Ersteres ist besser - jedoch ist es sinnvoll die std::string's als const std::string&amp; zu übergeben, so werden sie nicht kopiert.</p>
<p>std::string's haben gegenüber C-Strings viele Vorteile - suche mal hier im Forum danach.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2185633</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2185633</guid><dc:creator><![CDATA[theta]]></dc:creator><pubDate>Sat, 25 Feb 2012 15:51:48 GMT</pubDate></item><item><title><![CDATA[Reply to Kurze Design Frage on Sat, 25 Feb 2012 15:57:24 GMT]]></title><description><![CDATA[<p>Wenn du nur C-Strings brauchst, dann nimm C-Strings.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2185637</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2185637</guid><dc:creator><![CDATA[sdfjse]]></dc:creator><pubDate>Sat, 25 Feb 2012 15:57:24 GMT</pubDate></item><item><title><![CDATA[Reply to Kurze Design Frage on Sat, 25 Feb 2012 16:24:40 GMT]]></title><description><![CDATA[<p>sdfjse schrieb:</p>
<blockquote>
<p>Wenn du nur C-Strings brauchst, dann nimm C-Strings.</p>
</blockquote>
<p><img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f44d.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--thumbs_up"
      title=":+1:"
      alt="👍"
    /><br />
Aber trotzdem: Nimm const char*!</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2185646</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2185646</guid><dc:creator><![CDATA[cooky451]]></dc:creator><pubDate>Sat, 25 Feb 2012 16:24:40 GMT</pubDate></item><item><title><![CDATA[Reply to Kurze Design Frage on Sat, 25 Feb 2012 16:26:03 GMT]]></title><description><![CDATA[<p>Komm mal ins IRC cooky :&lt;</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2185647</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2185647</guid><dc:creator><![CDATA[314159265358979]]></dc:creator><pubDate>Sat, 25 Feb 2012 16:26:03 GMT</pubDate></item><item><title><![CDATA[Reply to Kurze Design Frage on Sat, 25 Feb 2012 16:48:53 GMT]]></title><description><![CDATA[<p>Okay aber wie gebe ich einen C String richtig ein.</p>
<p>So stürtzt mir das Programm ab: <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f61e.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--disappointed_face"
      title=":("
      alt="😞"
    /></p>
<pre><code class="language-cpp">my_class obj;
char *str=0;

cin&gt;&gt;str;
obj.VerbindeZuServer ( str,&quot;test&quot;,&quot;test&quot; );
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2185655</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2185655</guid><dc:creator><![CDATA[CptQuak]]></dc:creator><pubDate>Sat, 25 Feb 2012 16:48:53 GMT</pubDate></item><item><title><![CDATA[Reply to Kurze Design Frage on Sat, 25 Feb 2012 16:56:14 GMT]]></title><description><![CDATA[<p>CptQuak schrieb:</p>
<blockquote>
<p>Okay aber wie gebe ich einen C String richtig ein.</p>
</blockquote>
<p>Nur weil du einen C String übergibst, heißt das nicht, dass du ihn auch zur Eingabe nutzt. (Da nutzt du lieber std::string) (Zudem hast du das Speicherkonzept wohl überhaupt nicht verstanden..)</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2185658</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2185658</guid><dc:creator><![CDATA[cooky451]]></dc:creator><pubDate>Sat, 25 Feb 2012 16:56:14 GMT</pubDate></item><item><title><![CDATA[Reply to Kurze Design Frage on Sat, 25 Feb 2012 17:11:54 GMT]]></title><description><![CDATA[<pre><code class="language-cpp">char *var = &quot;ABC&quot;; // Reserviert mir 3 Byte + 1 Byte Nullterminator
Im Speicher: [41][42][43][0]

char *var=0; // Zeigt auf gar nichts, var braucht eine Adresse wo es drauf zeigen kann
</code></pre>
<p>Das ist doch so richtig oder? Wenn nicht korrigiert micht plz.</p>
<p>Bsp. 1</p>
<pre><code class="language-cpp">int VerbindeZuServer(const char* srvname, const char* username, const char* password );

int main () 
{
std::string var;

cin&gt;&gt;var;

VerbindeZuServer(var.c_str() , &quot;test&quot;,&quot;test&quot;); // c_str() wird hier einmal aufgerufen

}

int VerbindeZuServer(const char* srvname, const char* username, const char* password )
{
InternetConnect( hinternet, servername  , INTERNET_DEFAULT_FTP_PORT, username, password,
					INTERNET_SERVICE_FTP, INTERNET_FLAG_PASSIVE, NULL );
}
</code></pre>
<p>Bsp. 2</p>
<pre><code class="language-cpp">int VerbindeZuServer(std::string srvname, std::string username, std::string password )

int main()
{
std::string var;

cin&gt;&gt;var;

VerbindeZuServer(var.c_str() , &quot;test&quot;,&quot;test&quot;); // c_str() wird hier einmal aufgerufen
}

int VerbindeZuServer(std::string srvname, std::string username, std::string password )
{

// Hier wird .c_str() noch 2 weitere male aufgerufen
InternetConnect( hinternet, servername.c_str()  , INTERNET_DEFAULT_FTP_PORT, username.c_str(), password.c_str(),
					INTERNET_SERVICE_FTP, INTERNET_FLAG_PASSIVE, NULL );

}
</code></pre>
<p>Wäre ein Grund Bsp.1 zu benutzen da ich dort im Programm die Funktion .c_str() ja nur insgesamt einmal aufrufe?</p>
<p>Und in Bsp.2 rufe ich .c_str() ja sogar schon 3 mal auf. (Ich denke mal Bsp.2 kostet auch mehr Zeit in der ausführung )</p>
<p>Ist das so richtig?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2185675</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2185675</guid><dc:creator><![CDATA[CptQuak]]></dc:creator><pubDate>Sat, 25 Feb 2012 17:11:54 GMT</pubDate></item><item><title><![CDATA[Reply to Kurze Design Frage on Sat, 25 Feb 2012 17:12:53 GMT]]></title><description><![CDATA[<p>Oops sry hab mich bei den Funktionsparametern mit den Namen gerade vertan ... -.-<br />
(Aber egal das gehört ja jetzt net zum Thema)</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2185678</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2185678</guid><dc:creator><![CDATA[CptQuak]]></dc:creator><pubDate>Sat, 25 Feb 2012 17:12:53 GMT</pubDate></item><item><title><![CDATA[Reply to Kurze Design Frage on Sat, 25 Feb 2012 17:13:15 GMT]]></title><description><![CDATA[<p>CptQuak schrieb:</p>
<blockquote>
<p>Das ist doch so richtig oder? Wenn nicht korrigiert micht plz.</p>
</blockquote>
<p><a href="http://www.c-plusplus.net/forum/299061" rel="nofollow">http://www.c-plusplus.net/forum/299061</a></p>
]]></description><link>https://www.c-plusplus.net/forum/post/2185679</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2185679</guid><dc:creator><![CDATA[cooky451]]></dc:creator><pubDate>Sat, 25 Feb 2012 17:13:15 GMT</pubDate></item></channel></rss>