<?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[Ofstream - Dateiausgabe]]></title><description><![CDATA[<p>Hi bin neu hier, wir haben eine Programmierübung. Ich habe sie mit Visual Studio 2008 gemacht und kompiliert. Es kommen auch keine Fehler. Bei einer Teilaufgabe hab ich noch ein Problem:</p>
<p>Aufgabe 1A):</p>
<p>Schreiben Sie eine kleine Funktion createTestFile(), die eine neue Datei<br />
„tmp.txt“ im aktuellen Verzeichnis anlegt und einen kleinen Text in die Datei<br />
schreibt. Der Text sollte insbesondere folgende Elemente enthalten:<br />
Zeilenumbrüche, Tabulatoren, Umlaute.<br />
Testen Sie die Funktion, indem Sie sich das Ergebnis mit einem Texteditor<br />
anschauen. Jetzt wollen wir es aber genauer wissen: Wie ist der Text tatsächlich<br />
auf Byte-Ebene codiert?</p>
<p>void createTestFile() {<br />
ofstream of(&quot;tmp.txt&quot;);<br />
of &lt;&lt; &quot;abc\tdef\nghi&quot; &lt;&lt; endl &lt;&lt; &quot;äöüß&quot;;<br />
of.close();<br />
}</p>
<p>(includes hab ich weggelassen, jedoch im meinem Gesamtcode drin)</p>
<p>das hab ich als code geschriebn. Visual Studio nimmts auch an, das Problem ist, ich finde nirgendswo die tmp.txt. Die erstellt er mir quasi nicht. (Der gesamte Code der Aufgabe ist natürlich länger, da hat auch alles geklappt nur bei der Teilaufgabe nicht)</p>
<p>Liegt es vllt an den Einstellung von Visuals Studio das es nicht klappt?</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/253952/ofstream-dateiausgabe</link><generator>RSS for Node</generator><lastBuildDate>Sun, 13 Sep 2026 04:20:20 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/253952.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 09 Nov 2009 16:12:47 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Ofstream - Dateiausgabe on Mon, 09 Nov 2009 16:12:47 GMT]]></title><description><![CDATA[<p>Hi bin neu hier, wir haben eine Programmierübung. Ich habe sie mit Visual Studio 2008 gemacht und kompiliert. Es kommen auch keine Fehler. Bei einer Teilaufgabe hab ich noch ein Problem:</p>
<p>Aufgabe 1A):</p>
<p>Schreiben Sie eine kleine Funktion createTestFile(), die eine neue Datei<br />
„tmp.txt“ im aktuellen Verzeichnis anlegt und einen kleinen Text in die Datei<br />
schreibt. Der Text sollte insbesondere folgende Elemente enthalten:<br />
Zeilenumbrüche, Tabulatoren, Umlaute.<br />
Testen Sie die Funktion, indem Sie sich das Ergebnis mit einem Texteditor<br />
anschauen. Jetzt wollen wir es aber genauer wissen: Wie ist der Text tatsächlich<br />
auf Byte-Ebene codiert?</p>
<p>void createTestFile() {<br />
ofstream of(&quot;tmp.txt&quot;);<br />
of &lt;&lt; &quot;abc\tdef\nghi&quot; &lt;&lt; endl &lt;&lt; &quot;äöüß&quot;;<br />
of.close();<br />
}</p>
<p>(includes hab ich weggelassen, jedoch im meinem Gesamtcode drin)</p>
<p>das hab ich als code geschriebn. Visual Studio nimmts auch an, das Problem ist, ich finde nirgendswo die tmp.txt. Die erstellt er mir quasi nicht. (Der gesamte Code der Aufgabe ist natürlich länger, da hat auch alles geklappt nur bei der Teilaufgabe nicht)</p>
<p>Liegt es vllt an den Einstellung von Visuals Studio das es nicht klappt?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1805603</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1805603</guid><dc:creator><![CDATA[Quattle]]></dc:creator><pubDate>Mon, 09 Nov 2009 16:12:47 GMT</pubDate></item><item><title><![CDATA[Reply to Ofstream - Dateiausgabe on Mon, 09 Nov 2009 16:48:57 GMT]]></title><description><![CDATA[<p>Such mal genauer, dein Code ist an sich richtig. Denk daran, dass die Datei im aktuellen Verzeichnis erstellt wird. Je nachdem, wie du dein Programm startest, kann das etwas ziemlich unerwartetes sein.</p>
<p>P.S.: Für Code nimmt man am Besten die CPP-Tags (links unter den Smileys, dann kann man das viel besser lesen, schau mal:</p>
<pre><code class="language-cpp">void createTestFile() {
 ofstream of(&quot;tmp.txt&quot;);
 of &lt;&lt; &quot;abc\tdef\nghi&quot; &lt;&lt; endl &lt;&lt; &quot;äöüß&quot;;
 of.close();
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1805632</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1805632</guid><dc:creator><![CDATA[SeppJ]]></dc:creator><pubDate>Mon, 09 Nov 2009 16:48:57 GMT</pubDate></item><item><title><![CDATA[Reply to Ofstream - Dateiausgabe on Mon, 09 Nov 2009 19:33:38 GMT]]></title><description><![CDATA[<p>Normalerweise (wenn du nix an den Einstellungen änderst) sollte die Datei im Verzeichnis, wo die Projektdateien liegen vorhanden sein. (Wenn du von der IDE aus startest)<br />
Ansonsten befindet sich die Datei im Ordner, wo du die .exe startest.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1805744</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1805744</guid><dc:creator><![CDATA[drakon]]></dc:creator><pubDate>Mon, 09 Nov 2009 19:33:38 GMT</pubDate></item><item><title><![CDATA[Reply to Ofstream - Dateiausgabe on Mon, 09 Nov 2009 19:47:54 GMT]]></title><description><![CDATA[<p>Hallo</p>
<p>welches BS verwendest du</p>
<p>Mfg<br />
Klaus</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1805755</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1805755</guid><dc:creator><![CDATA[KlausB]]></dc:creator><pubDate>Mon, 09 Nov 2009 19:47:54 GMT</pubDate></item><item><title><![CDATA[Reply to Ofstream - Dateiausgabe on Mon, 09 Nov 2009 19:51:29 GMT]]></title><description><![CDATA[<p>Windows XP Professional verwende ich.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1805758</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1805758</guid><dc:creator><![CDATA[Quattle]]></dc:creator><pubDate>Mon, 09 Nov 2009 19:51:29 GMT</pubDate></item><item><title><![CDATA[Reply to Ofstream - Dateiausgabe on Mon, 09 Nov 2009 19:52:47 GMT]]></title><description><![CDATA[<p>Hallo</p>
<p>und ueber die SF von WinXP findest du<br />
die Datei nicht</p>
<p>Mfg<br />
Klaus</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1805759</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1805759</guid><dc:creator><![CDATA[KlausB]]></dc:creator><pubDate>Mon, 09 Nov 2009 19:52:47 GMT</pubDate></item><item><title><![CDATA[Reply to Ofstream - Dateiausgabe on Mon, 09 Nov 2009 19:55:56 GMT]]></title><description><![CDATA[<p>Das ist mein gesamter Code von meiner Aufgabe:</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;iomanip&gt;
#include &lt;fstream&gt;
#include &lt;string&gt;
#include &lt;limits&gt;
using namespace std;

class FileAnalyzer {
private:

	ifstream stream;

	unsigned char* buffer;

	int bSize;

	int bLength;

	int bOffset;

	int columns;

	void printLine(int bIdxFrom, int bIdxTo);

public:

	FileAnalyzer(string fileName, int cols = 10, int rows = 20);

	~FileAnalyzer();

	bool hasMoreData();

	void analyze(int offset);

	void analyzePrev();

	void analyzeNext();

	void analyzeAll();
};

FileAnalyzer::FileAnalyzer(string fileName, int cols, int rows)
	: bSize(cols * rows), bLength(0), bOffset(0), columns(cols) {
	stream.open(fileName.c_str(), ios::in | ios::binary);
	buffer = new unsigned char[bSize];
}

FileAnalyzer::~FileAnalyzer() {
	stream.close();
	delete[] buffer;
}

bool FileAnalyzer::hasMoreData() {
	return !stream.eof();
}

void FileAnalyzer::analyze(int offset) {
	char c;
	bOffset = offset;
	if (stream.fail())
		stream.clear(); 
	stream.seekg(bOffset); 

	for (bLength = 0; stream.get(c) &amp;&amp; bLength &lt; bSize; bLength++) {
		buffer[bLength] = c;
	}

	for (int idx = 0; idx &lt; bLength; idx+=columns)
		printLine(idx, min(bLength, idx+columns));
}

void FileAnalyzer::analyzePrev() {
	analyze(max(bOffset-bSize, 0));
}

void FileAnalyzer::analyzeNext() {
	if (hasMoreData()) 
		bOffset+=bSize;
	analyze(bOffset);
}

void FileAnalyzer::analyzeAll() {
	analyze(0);
	while (hasMoreData())
		analyzeNext();
}

void FileAnalyzer::printLine(int bIdxFrom, int bIdxTo) {

	cout &lt;&lt; setw(8) &lt;&lt; bOffset + bIdxFrom &lt;&lt; &quot;: &quot; &lt;&lt; hex;

	for (int i = bIdxFrom; i &lt; bIdxFrom + columns; i++) {
		if (i &lt; bIdxTo)
			cout &lt;&lt; setw(2) &lt;&lt; (short) buffer[i] &lt;&lt; &quot; &quot;;
		else
			cout &lt;&lt; &quot;   &quot;;
	}
	cout &lt;&lt; dec &lt;&lt; &quot;  |   &quot;;

	for (int i = bIdxFrom; i &lt; bIdxTo; i++) {
		if (buffer[i] &gt;= 0x20 &amp;&amp; buffer[i] &lt; 0x7f) 
			cout &lt;&lt; buffer[i]; 
		else
			cout &lt;&lt; &quot;?&quot;; 
	}
	cout &lt;&lt; endl;
}

void createTestFile() {
	ofstream of(&quot;tmp.txt&quot;);
	of &lt;&lt; &quot;abc\tdef\nghi&quot; &lt;&lt; endl &lt;&lt; &quot;äöüß&quot;;
	of.close();
}

int main() {

	int choice = 4;
	int pos = 0;
	string fileName;
	cout &lt;&lt; &quot;File Analyzer\nSpecify a file and I show you every bit of it!&quot;
		&lt;&lt; &quot;\n\nfile name: &quot;;
	cin &gt;&gt; fileName;
	FileAnalyzer f(fileName);
	do {
		cout &lt;&lt; endl;
		switch (choice) {
			case 1:
				f.analyzePrev(); break;
			case 2:
				f.analyzeNext(); break;
			case 3:
				f.analyzeAll(); break;
			case 4:
				f.analyze(pos);
		}
		cout &lt;&lt; &quot;\n(1) prev   (2) next   (3) all   (4) specify pos   (0) exit : &quot;;
		cin &gt;&gt; choice;
		if (choice == 4) {
			cout &lt;&lt; &quot;position: &quot;;
			cin &gt;&gt; pos;
		}
		if (cin.fail()) { 
			cin.clear();  
			cin.ignore(std::numeric_limits&lt;int&gt;::max(),'\n'); 
			choice = -1;  
		}
	} while (choice != 0);
}
</code></pre>
<p>Die Klasse bin ich gewohnt immer zusammen mit in eine Datei reinzupacken weil ich mit dem Class-Wizard nicht zurecht komme.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1805761</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1805761</guid><dc:creator><![CDATA[Quattle]]></dc:creator><pubDate>Mon, 09 Nov 2009 19:55:56 GMT</pubDate></item><item><title><![CDATA[Reply to Ofstream - Dateiausgabe on Mon, 09 Nov 2009 20:10:05 GMT]]></title><description><![CDATA[<blockquote>
<p>Jetzt wollen wir es aber genauer wissen: Wie ist der Text tatsächlich auf Byte-Ebene codiert?</p>
</blockquote>
<p>wer denkt sich denn so ne aufgabe aus? was will der denn da wissen? ascii?!<br />
implementierungs- bzw. plattform-abhängig?</p>
<p>ich hoffe, in der original-aufgabenstellung ist das besser formuliert.<br />
ansonsten würd ich ihm genau so antworten, wie er fragt:<br />
&quot;ist mit 0en und 1en codiert...&quot;</p>
<p>deine datei sollte wie gesagt im selben ordner liegen, in dem auch dein projekt liegt(ggf noch eine ebene tiefer, wenn du den haken am anfang(&quot;create subdirectory&quot; oder so ähnlich) nicht rausgemacht hast)...<br />
wenn das nicht der fall ist, guck mal, was bei working-directory eingetragen ist(rechtsklick im solutionexplorer auf deinen projektnamen -&gt; propertys -&gt; debugging -&gt; worikng directory)</p>
<p>bb</p>
<p>edit:<br />
rechtsklick im solutionexplorer auf deinen projektnamen(das fette) -&gt; propertys -&gt; debugging -&gt; worikng directory -&gt; linksklick in das feld -&gt; &lt;Browse&gt;</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1805764</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1805764</guid><dc:creator><![CDATA[unskilled]]></dc:creator><pubDate>Mon, 09 Nov 2009 20:10:05 GMT</pubDate></item><item><title><![CDATA[Reply to Ofstream - Dateiausgabe on Mon, 09 Nov 2009 20:15:40 GMT]]></title><description><![CDATA[<p>rechtsklick im solutionexplorer auf deinen projektnamen(das fette) -&gt; propertys -&gt; debugging -&gt; worikng directory -&gt; linksklick in das feld -&gt; &lt;Browse&gt;</p>
<p>Also das hab ich jetzt gemacht und extra da mein Ordner eingetippt, aber da war es dann immer noch nicht wo ich es nochmal durchlaufen lassen hab...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1805771</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1805771</guid><dc:creator><![CDATA[Quattle]]></dc:creator><pubDate>Mon, 09 Nov 2009 20:15:40 GMT</pubDate></item><item><title><![CDATA[Reply to Ofstream - Dateiausgabe on Mon, 09 Nov 2009 20:29:47 GMT]]></title><description><![CDATA[<p>unskilled schrieb:</p>
<blockquote>
<p>ich hoffe, in der original-aufgabenstellung ist das besser formuliert.<br />
ansonsten würd ich ihm genau so antworten, wie er fragt:<br />
&quot;ist mit 0en und 1en codiert...&quot;</p>
</blockquote>
<p>Nicht, wenn die Datei beispielsweise mein Drucker ist...</p>
<p>Ist tatsächlich nicht zu beantworten, diese Frage.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1805778</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1805778</guid><dc:creator><![CDATA[SeppJ]]></dc:creator><pubDate>Mon, 09 Nov 2009 20:29:47 GMT</pubDate></item><item><title><![CDATA[Reply to Ofstream - Dateiausgabe on Mon, 09 Nov 2009 20:33:18 GMT]]></title><description><![CDATA[<p>Quattle schrieb:</p>
<blockquote>
<p>rechtsklick im solutionexplorer auf deinen projektnamen(das fette) -&gt; propertys -&gt; debugging -&gt; worikng directory -&gt; linksklick in das feld -&gt; &lt;Browse&gt;</p>
<p>Also das hab ich jetzt gemacht und extra da mein Ordner eingetippt, aber da war es dann immer noch nicht wo ich es nochmal durchlaufen lassen hab...</p>
</blockquote>
<p>dann guck mal, was is_open() (oder good() - ist egal, was von beiden) zurückliefert...</p>
<p>bis gleich ;o)</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1805784</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1805784</guid><dc:creator><![CDATA[unskilled]]></dc:creator><pubDate>Mon, 09 Nov 2009 20:33:18 GMT</pubDate></item><item><title><![CDATA[Reply to Ofstream - Dateiausgabe on Mon, 09 Nov 2009 20:45:35 GMT]]></title><description><![CDATA[<p>also is_open() einfach in meinen code hinzufügen?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1805792</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1805792</guid><dc:creator><![CDATA[Quattle]]></dc:creator><pubDate>Mon, 09 Nov 2009 20:45:35 GMT</pubDate></item><item><title><![CDATA[Reply to Ofstream - Dateiausgabe on Mon, 09 Nov 2009 20:50:09 GMT]]></title><description><![CDATA[<pre><code class="language-cpp">void createTestFile() { 
    ofstream of(&quot;tmp.txt&quot;); 
    of &lt;&lt; &quot;abc\tdef\nghi&quot; &lt;&lt; endl &lt;&lt; &quot;äöüß&quot;; 
    of.close(); 
}
</code></pre>
<p>hier z.bsp. ein<br />
<code>std::cout &lt;&lt; &quot;Geoeffnet: &quot; &lt;&lt; of.is_open() &lt;&lt; std::endl;</code><br />
hinzufügen.(nach dem <code>ofstream of(...)</code> und vor dem <code>of.close()</code> . Und dann sagen, was auf der Konsole stand...<br />
das of.close() ist übrigens überflüssig.</p>
<p>bb</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1805794</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1805794</guid><dc:creator><![CDATA[unskilled]]></dc:creator><pubDate>Mon, 09 Nov 2009 20:50:09 GMT</pubDate></item><item><title><![CDATA[Reply to Ofstream - Dateiausgabe on Mon, 09 Nov 2009 20:56:33 GMT]]></title><description><![CDATA[<p>Also ich habs hinzugfügt, komischerweise zeigt er in der Konsole nichts anderes an. Mir kommt das jetzt echt komisch vor</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1805799</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1805799</guid><dc:creator><![CDATA[Quattle]]></dc:creator><pubDate>Mon, 09 Nov 2009 20:56:33 GMT</pubDate></item><item><title><![CDATA[Reply to Ofstream - Dateiausgabe on Mon, 09 Nov 2009 21:06:34 GMT]]></title><description><![CDATA[<p>Ist nicht dein Ernst, oder? Wer kommt denn bitte darauf, dass du die Fkt nicht mal aufrufst, die die Datei erzeugt? xD</p>
<p>Von wem hast du den Quelltext denn kopiert? Langsam scheint es mir so, als ob das nicht selbst geschrieben haben kannst...</p>
<p>bb</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1805804</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1805804</guid><dc:creator><![CDATA[unskilled]]></dc:creator><pubDate>Mon, 09 Nov 2009 21:06:34 GMT</pubDate></item><item><title><![CDATA[Reply to Ofstream - Dateiausgabe on Tue, 10 Nov 2009 09:09:51 GMT]]></title><description><![CDATA[<p>In deinen Quelltext wird die Funktion in der main nicht aufgerufen..</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1805897</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1805897</guid><dc:creator><![CDATA[moinaufruf]]></dc:creator><pubDate>Tue, 10 Nov 2009 09:09:51 GMT</pubDate></item><item><title><![CDATA[Reply to Ofstream - Dateiausgabe on Tue, 10 Nov 2009 15:42:37 GMT]]></title><description><![CDATA[<p>moinaufruf schrieb:</p>
<blockquote>
<p>In deinen Quelltext wird die Funktion in der main nicht aufgerufen..</p>
</blockquote>
<p>danke, dass du das noch mal so klar formulierst - vll war meine aussage ja zu schwammig... ~~</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1806096</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1806096</guid><dc:creator><![CDATA[unskilled]]></dc:creator><pubDate>Tue, 10 Nov 2009 15:42:37 GMT</pubDate></item></channel></rss>