<?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[In externe Datei speichern]]></title><description><![CDATA[<p>Hallo,<br />
ich versuche eine Variable in eine externe Datei zu schreiben. Und zwar so:</p>
<pre><code>FILE *fp;
if((fp=fopen(&quot;namen.txt&quot;,&quot;w&quot;))==NULL);
fprintf(fp,&quot;%s &quot;,name);
fclose(fp);
</code></pre>
<p>Jetzt wird aber in die externe Datei aber immer nur der erste Buchstabe der Variable &quot;Name&quot; geschrieben. Ich möchte natürlich das die komplette Variable in der txt-Datei landet.</p>
<p>Was mache ich falsch?</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/244059/in-externe-datei-speichern</link><generator>RSS for Node</generator><lastBuildDate>Sat, 19 Sep 2026 13:26:23 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/244059.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 24 Jun 2009 14:52:06 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to In externe Datei speichern on Wed, 24 Jun 2009 14:52:06 GMT]]></title><description><![CDATA[<p>Hallo,<br />
ich versuche eine Variable in eine externe Datei zu schreiben. Und zwar so:</p>
<pre><code>FILE *fp;
if((fp=fopen(&quot;namen.txt&quot;,&quot;w&quot;))==NULL);
fprintf(fp,&quot;%s &quot;,name);
fclose(fp);
</code></pre>
<p>Jetzt wird aber in die externe Datei aber immer nur der erste Buchstabe der Variable &quot;Name&quot; geschrieben. Ich möchte natürlich das die komplette Variable in der txt-Datei landet.</p>
<p>Was mache ich falsch?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1732205</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1732205</guid><dc:creator><![CDATA[Anbo]]></dc:creator><pubDate>Wed, 24 Jun 2009 14:52:06 GMT</pubDate></item><item><title><![CDATA[Reply to In externe Datei speichern on Wed, 24 Jun 2009 15:09:35 GMT]]></title><description><![CDATA[<p>// Da falsch bzw. kein Lösungsansatz gelöscht.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1732209</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1732209</guid><dc:creator><![CDATA[inflames2k]]></dc:creator><pubDate>Wed, 24 Jun 2009 15:09:35 GMT</pubDate></item><item><title><![CDATA[Reply to In externe Datei speichern on Wed, 24 Jun 2009 15:08:53 GMT]]></title><description><![CDATA[<p>Für den Fall dass du nicht C machst (wie es aussieht), sondern tatsächlich C++(weil du ins C++-Forum geschrieben hast), solltest du das ganze völlig anders angehen, nämlich mit iostreams. Das sähe dann so aus:</p>
<pre><code class="language-cpp">#include&lt;iostream&gt;
#include&lt;fstream&gt;

[...]

std::ofstream file(&quot;namen.txt&quot;);
if (file.is_open()) {
 file&lt;&lt;name;
 file.close();
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1732213</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1732213</guid><dc:creator><![CDATA[SeppJ]]></dc:creator><pubDate>Wed, 24 Jun 2009 15:08:53 GMT</pubDate></item><item><title><![CDATA[Reply to In externe Datei speichern on Wed, 24 Jun 2009 15:28:44 GMT]]></title><description><![CDATA[<p>Ja ich mach das in C++. Aber wenn ich das so mache wie du meinst, dann bekomme ich da nur Unsinn raus. Wenn ich z.b. in der Variable den Namen &quot;anbo&quot; drin hab dann schreibt der in die externe Datei &quot;0034DC70&quot;.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1732230</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1732230</guid><dc:creator><![CDATA[Anbo]]></dc:creator><pubDate>Wed, 24 Jun 2009 15:28:44 GMT</pubDate></item><item><title><![CDATA[Reply to In externe Datei speichern on Wed, 24 Jun 2009 16:57:59 GMT]]></title><description><![CDATA[<p>Also das scheint so zu klappen nur mit der Variable nicht, weil wenn ich folgendes schreibe:</p>
<pre><code>std::ofstream file(&quot;namen.txt&quot;);
if (file.is_open())
{
 file &lt;&lt; name &lt;&lt; &quot;hallo&quot;;
 file.close();
}
</code></pre>
<p>dann steht &quot;0034DC70hallo&quot; in der Datei.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1732271</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1732271</guid><dc:creator><![CDATA[Anbo]]></dc:creator><pubDate>Wed, 24 Jun 2009 16:57:59 GMT</pubDate></item><item><title><![CDATA[Reply to In externe Datei speichern on Wed, 24 Jun 2009 17:14:15 GMT]]></title><description><![CDATA[<p>Dann ist die Lösung ganz einfach: Zeig mal was name für einen Typ hat! Ich wette, du hast da sowas wie char*.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1732278</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1732278</guid><dc:creator><![CDATA[SeppJ]]></dc:creator><pubDate>Wed, 24 Jun 2009 17:14:15 GMT</pubDate></item><item><title><![CDATA[Reply to In externe Datei speichern on Wed, 24 Jun 2009 17:48:27 GMT]]></title><description><![CDATA[<p>Muss man einen Zeiger nicht nach void* casten, wenn man seine Adresse schreiben möchte?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1732295</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1732295</guid><dc:creator><![CDATA[C++-Newb]]></dc:creator><pubDate>Wed, 24 Jun 2009 17:48:27 GMT</pubDate></item><item><title><![CDATA[Reply to In externe Datei speichern on Wed, 24 Jun 2009 18:35:36 GMT]]></title><description><![CDATA[<p>name hat den Typ CString.</p>
<pre><code>CString name;
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1732315</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1732315</guid><dc:creator><![CDATA[Anbo]]></dc:creator><pubDate>Wed, 24 Jun 2009 18:35:36 GMT</pubDate></item><item><title><![CDATA[Reply to In externe Datei speichern on Wed, 24 Jun 2009 19:13:31 GMT]]></title><description><![CDATA[<p>Dann wird CString wohl keinen &lt;&lt; Operator für streams besitzen.<br />
Das beste wäre wenn du statt CString std::string verwendest.<br />
Ansonsten musst du den CString entweder erstmal nach char* oder eben std::string konvertieren.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1732335</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1732335</guid><dc:creator><![CDATA[rean]]></dc:creator><pubDate>Wed, 24 Jun 2009 19:13:31 GMT</pubDate></item><item><title><![CDATA[Reply to In externe Datei speichern on Wed, 24 Jun 2009 19:54:43 GMT]]></title><description><![CDATA[<p>Deshalb wollt ich es ja so machen wie ich es am Anfang gepostet habe. Aber das geht irgendwie nicht. Obwohl das ja auch klappen müsste.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1732366</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1732366</guid><dc:creator><![CDATA[Anbo]]></dc:creator><pubDate>Wed, 24 Jun 2009 19:54:43 GMT</pubDate></item><item><title><![CDATA[Reply to In externe Datei speichern on Thu, 25 Jun 2009 07:12:17 GMT]]></title><description><![CDATA[<p>Nun, wieso sollte printf, dass nur mit nativen C Datentypen vernünftig umgehen kann auf einmal etwas mit Cstring anfangen können? Ist das nicht irgendeine MFC-Klasse? Vielleicht hilft dies weiter:<br />
<a href="http://www.c-plusplus.net/forum/viewtopic-var-t-is-39103.html" rel="nofollow">http://www.c-plusplus.net/forum/viewtopic-var-t-is-39103.html</a></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1732495</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1732495</guid><dc:creator><![CDATA[SeppJ]]></dc:creator><pubDate>Thu, 25 Jun 2009 07:12:17 GMT</pubDate></item><item><title><![CDATA[Reply to In externe Datei speichern on Thu, 25 Jun 2009 19:28:59 GMT]]></title><description><![CDATA[<p>Ok, jetzt habe ich das mit iostream gelöst. Dann hab ich noch eine Frage wie kann ich damit die Daten aus der externen Datei in eine Variable speichern?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1732891</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1732891</guid><dc:creator><![CDATA[Anbo]]></dc:creator><pubDate>Thu, 25 Jun 2009 19:28:59 GMT</pubDate></item><item><title><![CDATA[Reply to In externe Datei speichern on Thu, 25 Jun 2009 19:57:27 GMT]]></title><description><![CDATA[<pre><code class="language-cpp">while( solange zeiger noch nicht am ende )
{
   hole zeile für zeile und speichere diese in einer variabe
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1732905</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1732905</guid><dc:creator><![CDATA[Kóyaánasqatsi]]></dc:creator><pubDate>Thu, 25 Jun 2009 19:57:27 GMT</pubDate></item><item><title><![CDATA[Reply to In externe Datei speichern on Thu, 25 Jun 2009 20:22:20 GMT]]></title><description><![CDATA[<p>Hat vielleicht auch noch wer ein Beispiel, wie ich das genau machen muss? Wäre echt nett.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1732923</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1732923</guid><dc:creator><![CDATA[Anbo]]></dc:creator><pubDate>Thu, 25 Jun 2009 20:22:20 GMT</pubDate></item><item><title><![CDATA[Reply to In externe Datei speichern on Thu, 25 Jun 2009 20:33:01 GMT]]></title><description><![CDATA[<p><a href="http://www.igooglethatforyou.com/?q=c%2B%2B+file+operations" rel="nofollow">Such selber!</a></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1732928</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1732928</guid><dc:creator><![CDATA[Kóyaánasqatsi]]></dc:creator><pubDate>Thu, 25 Jun 2009 20:33:01 GMT</pubDate></item><item><title><![CDATA[Reply to In externe Datei speichern on Thu, 25 Jun 2009 22:52:08 GMT]]></title><description><![CDATA[<p>Ein bisschen schlauer bin ich jetzt, aber so wirklich klappen tut das trotzdem nicht:</p>
<pre><code>std::ifstream file(&quot;namen.txt&quot;);
while(!file.eof())
{
	file&gt;&gt;name;
	printf(&quot;%s&quot;,name);
}
file.close();
</code></pre>
<p>Fehlermeldung von Mircosoft Visual Studio:<br />
Unbehandelte Ausnahme bei 0x104e63ee (msvcp90d.dll) in Programmname.exe: 0xC0000005: Zugriffsverletzung beim Schreiben an Position 0x00416814.</p>
<p>Was mache ich falsch?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1733008</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1733008</guid><dc:creator><![CDATA[Anbo]]></dc:creator><pubDate>Thu, 25 Jun 2009 22:52:08 GMT</pubDate></item><item><title><![CDATA[Reply to In externe Datei speichern on Fri, 26 Jun 2009 04:58:58 GMT]]></title><description><![CDATA[<p>Kurz und knapp, meiner meinung nach der einfachste weg, Daten von einer Datei in einen std::string zu schreiben. Du kannst natürlich auch was anderes als nen std::string nehmen.</p>
<pre><code class="language-cpp">std::ifstream file(&quot;namen.txt&quot;);
char ch;
while( file.get(ch) ) string.push_back(ch);
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1733047</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1733047</guid><dc:creator><![CDATA[Neo Gandar]]></dc:creator><pubDate>Fri, 26 Jun 2009 04:58:58 GMT</pubDate></item><item><title><![CDATA[Reply to In externe Datei speichern on Fri, 26 Jun 2009 12:50:56 GMT]]></title><description><![CDATA[<p>Da bekomme ich die Fehlermeldung:<br />
Links von &quot;.push_back&quot; muss sich eine Klasse/Struktur/Union befinden.</p>
<pre><code>std::ifstream file(&quot;namen.txt&quot;);
char ch;
while(file.get(ch))name.push_back(ch);
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1733296</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1733296</guid><dc:creator><![CDATA[Anbo]]></dc:creator><pubDate>Fri, 26 Jun 2009 12:50:56 GMT</pubDate></item><item><title><![CDATA[Reply to In externe Datei speichern on Fri, 26 Jun 2009 14:26:27 GMT]]></title><description><![CDATA[<p>name sollte hier vom Typ std::string sein.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1733362</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1733362</guid><dc:creator><![CDATA[Braunstein]]></dc:creator><pubDate>Fri, 26 Jun 2009 14:26:27 GMT</pubDate></item><item><title><![CDATA[Reply to In externe Datei speichern on Fri, 26 Jun 2009 14:29:22 GMT]]></title><description><![CDATA[<p>Anbo schrieb:</p>
<blockquote>
<p>Da bekomme ich die Fehlermeldung:<br />
Links von &quot;.push_back&quot; muss sich eine Klasse/Struktur/Union befinden.</p>
<pre><code>std::ifstream file(&quot;namen.txt&quot;);
char ch;
while(file.get(ch))name.push_back(ch);
</code></pre>
</blockquote>
<p>was meinst du, warum er string.push_back(ch) geschrieben hat?</p>
<p>tip - das fehlt noch:<br />
<code>#include &lt;string&gt;</code><br />
und<br />
<code>std::string name;</code></p>
<p>bb</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1733364</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1733364</guid><dc:creator><![CDATA[unskilled]]></dc:creator><pubDate>Fri, 26 Jun 2009 14:29:22 GMT</pubDate></item><item><title><![CDATA[Reply to In externe Datei speichern on Fri, 26 Jun 2009 15:39:32 GMT]]></title><description><![CDATA[<p>Ok, vielen Dank jetzt klappt alles.<br />
Dankeschön</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1733390</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1733390</guid><dc:creator><![CDATA[Anbo]]></dc:creator><pubDate>Fri, 26 Jun 2009 15:39:32 GMT</pubDate></item><item><title><![CDATA[Reply to In externe Datei speichern on Fri, 26 Jun 2009 17:31:15 GMT]]></title><description><![CDATA[<p>Aber so lädt der den kompletten Textinhalt in eine Variable. Was muss ich hier ändern damit er jede Zeile in eine neue Variable speichert?</p>
<pre><code>std::string name;

std::ifstream file(&quot;namen.txt&quot;);
char ch;
while(file.get(ch))name.push_back(ch);
file.close();
std::cout &lt;&lt; name;
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1733427</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1733427</guid><dc:creator><![CDATA[Anbo]]></dc:creator><pubDate>Fri, 26 Jun 2009 17:31:15 GMT</pubDate></item><item><title><![CDATA[Reply to In externe Datei speichern on Fri, 26 Jun 2009 17:38:54 GMT]]></title><description><![CDATA[<p>pssst:</p>
<p><a href="http://www.cplusplus.com/reference/iostream/istream/getline/" rel="nofollow">std::istream::getline</a></p>
<p>oder:<br />
<a href="http://www.cplusplus.com/reference/string/getline/" rel="nofollow">std::getline</a></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1733433</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1733433</guid><dc:creator><![CDATA[drakon]]></dc:creator><pubDate>Fri, 26 Jun 2009 17:38:54 GMT</pubDate></item></channel></rss>