<?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[Einen Text in eine Datei speichern -AUfgabe -]]></title><description><![CDATA[<p>Hallo ..<br />
kann mir bitte jemand helfen um diese Aufgabe zu lösen<br />
ich kome nicht klar was ich machen soll !!</p>
<p>&quot;&quot;(Ein Unternehmen vertreibt verschiedene Getränke. Oft stellen Kunden Fragen<br />
zu den Produkten. Damit die E-Mail mit den Fragen an den richtigen Mitarbeiter gelangt, soll ein Programm erkennen, um welche Produktsorte es geht und<br />
einen Text in eine Datei speichern. Das von Ihnen zu entwerfende Programm<br />
soll also in einem Text (einzulesen aus einer Datei, Dateiname wird abgefragt)<br />
Schlagworte (siehe Tabelle) suchen und je nach Ergebnis folgenden Text generieren und speichern:</p>
<p>Hi &lt;name&gt;, du hast eine neue Nachricht zum Thema &lt;buzzword&gt;.</p>
<p>buzzwordname ---name--- outputfile<br />
Kaffee ------------------Paul---- new_mail_to_Paul.txt<br />
Bohnen -----------------Paul---- new_mail_to_Paul.txt<br />
Saft----------------------- Phil ----new_mail_to_Phil.txt<br />
Wasser------------------ Phil---- new_mail_to_Phil.txt</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/350768/einen-text-in-eine-datei-speichern-aufgabe</link><generator>RSS for Node</generator><lastBuildDate>Mon, 07 Sep 2026 09:05:31 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/350768.rss" rel="self" type="application/rss+xml"/><pubDate>Sat, 08 Feb 2020 11:42:49 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Einen Text in eine Datei speichern -AUfgabe - on Sat, 08 Feb 2020 11:42:49 GMT]]></title><description><![CDATA[<p>Hallo ..<br />
kann mir bitte jemand helfen um diese Aufgabe zu lösen<br />
ich kome nicht klar was ich machen soll !!</p>
<p>&quot;&quot;(Ein Unternehmen vertreibt verschiedene Getränke. Oft stellen Kunden Fragen<br />
zu den Produkten. Damit die E-Mail mit den Fragen an den richtigen Mitarbeiter gelangt, soll ein Programm erkennen, um welche Produktsorte es geht und<br />
einen Text in eine Datei speichern. Das von Ihnen zu entwerfende Programm<br />
soll also in einem Text (einzulesen aus einer Datei, Dateiname wird abgefragt)<br />
Schlagworte (siehe Tabelle) suchen und je nach Ergebnis folgenden Text generieren und speichern:</p>
<p>Hi &lt;name&gt;, du hast eine neue Nachricht zum Thema &lt;buzzword&gt;.</p>
<p>buzzwordname ---name--- outputfile<br />
Kaffee ------------------Paul---- new_mail_to_Paul.txt<br />
Bohnen -----------------Paul---- new_mail_to_Paul.txt<br />
Saft----------------------- Phil ----new_mail_to_Phil.txt<br />
Wasser------------------ Phil---- new_mail_to_Phil.txt</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2586256</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2586256</guid><dc:creator><![CDATA[peter00]]></dc:creator><pubDate>Sat, 08 Feb 2020 11:42:49 GMT</pubDate></item><item><title><![CDATA[Reply to Einen Text in eine Datei speichern -AUfgabe - on Sat, 08 Feb 2020 11:52:25 GMT]]></title><description><![CDATA[<p><a class="plugin-mentions-user plugin-mentions-a" href="https://www.c-plusplus.net/forum/uid/36042">@peter00</a><br />
Du sollst <em>Hi Paul, du hast eine neue Nachricht zum Thema Kaffee.</em> in die Datei <em>new_mail_to_Paul.txt</em> schreiben. Usw.</p>
<p>Die Worte und Dateinamen musst du einlesen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2586258</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2586258</guid><dc:creator><![CDATA[[[global:former_user]]]]></dc:creator><pubDate>Sat, 08 Feb 2020 11:52:25 GMT</pubDate></item><item><title><![CDATA[Reply to Einen Text in eine Datei speichern -AUfgabe - on Sat, 08 Feb 2020 12:45:57 GMT]]></title><description><![CDATA[<p>@manni66<br />
aha ok also die datei new_mail_to_Paul.txt sollte vorhanden ?</p>
<p>so ist?</p>
<p>fstream file;<br />
file.open(&quot;new_mail_to_Paul.txt &quot;,ios::out | ios::app)<br />
file&gt;&gt;&quot;Hi Paul, du hast eine neue Nachricht zum Thema Kaffee&quot;<br />
file.close();</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2586269</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2586269</guid><dc:creator><![CDATA[peter00]]></dc:creator><pubDate>Sat, 08 Feb 2020 12:45:57 GMT</pubDate></item><item><title><![CDATA[Reply to Einen Text in eine Datei speichern -AUfgabe - on Sat, 08 Feb 2020 12:57:48 GMT]]></title><description><![CDATA[<p><a class="plugin-mentions-user plugin-mentions-a" href="https://www.c-plusplus.net/forum/uid/36042">@peter00</a> sagte in <a href="/forum/post/2586269">Einen Text in eine Datei speichern -AUfgabe -</a>:</p>
<blockquote>
<p>@manni66<br />
aha ok also die datei new_mail_to_Paul.txt sollte vorhanden ?</p>
</blockquote>
<p>Nein, warum?</p>
<blockquote>
<p>so ist?</p>
<p>fstream file;<br />
file.open(&quot;new_mail_to_Paul.txt &quot;,ios::out | ios::app)<br />
file&gt;&gt;&quot;Hi Paul, du hast eine neue Nachricht zum Thema Kaffee&quot;<br />
file.close();</p>
</blockquote>
<p>Dein Compiler sollte dazu eine Meinung haben.</p>
<p>Benutze ofstream, wenn du schreiben willst.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2586271</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2586271</guid><dc:creator><![CDATA[[[global:former_user]]]]></dc:creator><pubDate>Sat, 08 Feb 2020 12:57:48 GMT</pubDate></item><item><title><![CDATA[Reply to Einen Text in eine Datei speichern -AUfgabe - on Sat, 08 Feb 2020 13:09:39 GMT]]></title><description><![CDATA[<p>@manni66<br />
aha okay also so lautet den Code :</p>
<p>ofstream file;<br />
ofile.open(&quot;new_mail_to_Paul.txt &quot;)<br />
file&gt;&gt;&quot;Hi Paul, du hast eine neue Nachricht zum Thema Kaffee&quot;<br />
file.close();</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2586275</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2586275</guid><dc:creator><![CDATA[peter00]]></dc:creator><pubDate>Sat, 08 Feb 2020 13:09:39 GMT</pubDate></item><item><title><![CDATA[Reply to Einen Text in eine Datei speichern -AUfgabe - on Sat, 08 Feb 2020 13:44:17 GMT]]></title><description><![CDATA[<p><a class="plugin-mentions-user plugin-mentions-a" href="https://www.c-plusplus.net/forum/uid/36042">@peter00</a><br />
Nein. Benutze deinen Compiler!</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2586278</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2586278</guid><dc:creator><![CDATA[[[global:former_user]]]]></dc:creator><pubDate>Sat, 08 Feb 2020 13:44:17 GMT</pubDate></item><item><title><![CDATA[Reply to Einen Text in eine Datei speichern -AUfgabe - on Sun, 09 Feb 2020 16:31:33 GMT]]></title><description><![CDATA[<p><a class="plugin-mentions-user plugin-mentions-a" href="https://www.c-plusplus.net/forum/uid/36042">@peter00</a> Was hast Du in der Vorlesung gemacht?</p>
<pre><code class="language-cpp">#include &lt;cstdlib&gt;
#include &lt;stdexcept&gt;
#include &lt;utility&gt;
#include &lt;vector&gt;
#include &lt;string&gt;
#include &lt;sstream&gt;
#include &lt;fstream&gt;
#include &lt;iostream&gt;

int main()
{
	std::vector&lt;std::pair&lt;std::string, std::string&gt;&gt; buzzword_employee_map {
		{ &quot;Kaffee&quot;,  &quot;Paul&quot; },
		{ &quot;Bohnen&quot;,  &quot;Paul&quot; },
		{ &quot;Saft&quot;,    &quot;Phil&quot; },
		{ &quot;Wasser&quot;,  &quot;Phil&quot; }
	};

	auto output_filename_prefix{ &quot;new_mail_to_ &quot; };
	auto output_filename_postfix{ &quot;.txt&quot; };
	auto mail_greeting{ &quot;Hi&quot; };
	auto mail_body{ &quot;du hast eine neue Nachricht zum Thema &quot; };

	try {
		std::cout &lt;&lt; &quot;Filename?\n&quot;;
		std::string input_filename;
		if (!(std::cin &gt;&gt; input_filename))
			throw std::runtime_error{ &quot;Input error&quot; };
			
		std::ifstream is{ input_filename };
		if (!is.is_open())
			throw std::runtime_error{ &quot;File couldn't be opened for reading&quot; };
	
		std::string text(std::istreambuf_iterator&lt;char&gt;(is), {});
		std::string buzzword;
		std::string employee;
		for (auto pair : buzzword_employee_map) {
			std::cout &lt;&lt; pair.first &lt;&lt; '\n';
			if (text.find(pair.first) != text.npos) {
				buzzword = pair.first;
				employee = pair.second;
				break;
			}
		}

		if (!buzzword.length()) {
			std::cout &lt;&lt; &quot;No Buzzword found.\n\n&quot;;
			return EXIT_SUCCESS;
		}

		std::stringstream output_filename;
		output_filename &lt;&lt; output_filename_prefix &lt;&lt; employee &lt;&lt; output_filename_postfix;

		std::ofstream os{ output_filename.str() };
		if (!os.is_open())
			throw std::runtime_error{ &quot;File couldn't be opened for writing&quot; };
		
		os &lt;&lt; mail_greeting &lt;&lt; ' ' &lt;&lt; employee &lt;&lt; &quot;,\n&quot; &lt;&lt; mail_body &lt;&lt; buzzword &lt;&lt; &quot;.\n&quot;;
	}
	catch (std::runtime_error &amp; e) {
		std::cerr &lt;&lt; e.what() &lt;&lt; &quot; :(\n\n&quot;;
		return EXIT_FAILURE;
	}
	catch (...) {
		std::cerr &lt;&lt; &quot;An unknown error occured :(\n\n&quot;;
		return EXIT_FAILURE;
	}
}

</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2586302</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2586302</guid><dc:creator><![CDATA[Swordfish]]></dc:creator><pubDate>Sun, 09 Feb 2020 16:31:33 GMT</pubDate></item></channel></rss>