<?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[C++ strcpy funktioniert nicht richtig]]></title><description><![CDATA[<p>Hallo,</p>
<p>ich versuche die Funktion strncpy zu verwenden. Die Funktion soll den Typ string in char* umwandeln. Ich habe folgenden Code geschrieben.</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;fstream&gt;
#include &lt;string&gt;
using namespace std;

int main() {

//Lesen des Txt-Dokumentes wo der Pfad (C:\\) gespeichert ist.
string Pfad;
ifstream input(&quot;C:\\datei.txt&quot;);
string line;
while(std::getline(input, line))
  {
   Pfad=line;

  }
// Pfad ist jetzt C:\\
string WPfad;
WPfad=&quot;START &quot; + Pfad + &quot;internet.htm&quot;;
//WPfad ist jetzt &quot;START C:\\internet.htm&quot; (habe ich getestet).
char WPfad2 [200];
//Und jetzt die Umwandlung:
char* strcpy(char WPfad2, string WPfad);
//Umwandlung funktioniert nicht
cout &lt;&lt; WPfad2;
//Damit Fenster sich nicht schließt:
int tmp;
cin &gt;&gt; tmp; }
</code></pre>
<p>Der Sinn der Anwendung ist es statt cout, system(WPfad2) zu schreiben und das sich dann internet.htm öffnet. Da bei der Funktion system() keine Strings aktzeptiert werden, brauche ich strcpy(). Weiß jemand warum die Umwandlung mit strcpy() nicht funktioniert? Ich verwende Visual C++ 2008 Express Edition.</p>
<p>Danke schon jetzt für alle Antworten.</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/260130/c-strcpy-funktioniert-nicht-richtig</link><generator>RSS for Node</generator><lastBuildDate>Tue, 08 Sep 2026 11:13:50 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/260130.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 01 Feb 2010 14:05:42 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to C++ strcpy funktioniert nicht richtig on Mon, 01 Feb 2010 14:05:42 GMT]]></title><description><![CDATA[<p>Hallo,</p>
<p>ich versuche die Funktion strncpy zu verwenden. Die Funktion soll den Typ string in char* umwandeln. Ich habe folgenden Code geschrieben.</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;fstream&gt;
#include &lt;string&gt;
using namespace std;

int main() {

//Lesen des Txt-Dokumentes wo der Pfad (C:\\) gespeichert ist.
string Pfad;
ifstream input(&quot;C:\\datei.txt&quot;);
string line;
while(std::getline(input, line))
  {
   Pfad=line;

  }
// Pfad ist jetzt C:\\
string WPfad;
WPfad=&quot;START &quot; + Pfad + &quot;internet.htm&quot;;
//WPfad ist jetzt &quot;START C:\\internet.htm&quot; (habe ich getestet).
char WPfad2 [200];
//Und jetzt die Umwandlung:
char* strcpy(char WPfad2, string WPfad);
//Umwandlung funktioniert nicht
cout &lt;&lt; WPfad2;
//Damit Fenster sich nicht schließt:
int tmp;
cin &gt;&gt; tmp; }
</code></pre>
<p>Der Sinn der Anwendung ist es statt cout, system(WPfad2) zu schreiben und das sich dann internet.htm öffnet. Da bei der Funktion system() keine Strings aktzeptiert werden, brauche ich strcpy(). Weiß jemand warum die Umwandlung mit strcpy() nicht funktioniert? Ich verwende Visual C++ 2008 Express Edition.</p>
<p>Danke schon jetzt für alle Antworten.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1848539</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1848539</guid><dc:creator><![CDATA[marvin1234]]></dc:creator><pubDate>Mon, 01 Feb 2010 14:05:42 GMT</pubDate></item><item><title><![CDATA[Reply to C++ strcpy funktioniert nicht richtig on Mon, 01 Feb 2010 14:17:17 GMT]]></title><description><![CDATA[<p>system(WPfad.c_str());</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1848548</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1848548</guid><dc:creator><![CDATA[Fellhuhn]]></dc:creator><pubDate>Mon, 01 Feb 2010 14:17:17 GMT</pubDate></item><item><title><![CDATA[Reply to C++ strcpy funktioniert nicht richtig on Mon, 01 Feb 2010 14:29:06 GMT]]></title><description><![CDATA[<p>Fellhuhn schrieb:</p>
<blockquote>
<p>system(WPfad.c_str());</p>
</blockquote>
<p>Danke Fellhuhn.<br />
Jetzt funktioniert der Code. Der funktionierende Code ist jetzt:</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;fstream&gt;
#include &lt;string&gt;
using namespace std;

int main() {

//Lesen des Txt-Dokumentes wo der Pfad (C:\\) gespeichert ist.
string Pfad;
ifstream input(&quot;C:\\datei.txt&quot;);
string line;
while(std::getline(input, line))
  {
   Pfad=line;
  }
// Pfad ist jetzt C:\\
string WPfad;
WPfad=&quot;START &quot; + Pfad + &quot;internet.htm&quot;;
//WPfad ist jetzt &quot;START C:\\internet.htm&quot; (habe ich getestet).
char WPfad2 [200];
//Verändert:
cout &lt;&lt; WPfad.c_str();
//bzw.
system(WPfad.c_str();
//Damit Fenster sich nicht schließt:
int tmp;
cin &gt;&gt; tmp; }
</code></pre>
<p>Danke für die schnelle Antwort. <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="🙂"
    /> <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f4a1.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--light_bulb"
      title=":bulb:"
      alt="💡"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1848559</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1848559</guid><dc:creator><![CDATA[marvin1234]]></dc:creator><pubDate>Mon, 01 Feb 2010 14:29:06 GMT</pubDate></item><item><title><![CDATA[Reply to C++ strcpy funktioniert nicht richtig on Tue, 02 Feb 2010 15:08:08 GMT]]></title><description><![CDATA[<p>Übrigens:</p>
<pre><code class="language-cpp">//Und jetzt die Umwandlung: 
char* strcpy(char WPfad2, string WPfad);
</code></pre>
<p>Das ist eine Funktionsdeklaration und <strong>kein</strong> Funktionsaufruf, somit wird auch nichts umgewandelt.</p>
<pre><code class="language-cpp">char WPfad2 [200];
</code></pre>
<p>Das brauchst du ja jetzt nicht mehr.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1849207</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1849207</guid><dc:creator><![CDATA[Nexus]]></dc:creator><pubDate>Tue, 02 Feb 2010 15:08:08 GMT</pubDate></item></channel></rss>