<?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[Text in einem bestimmten Abschnitt eines anderen Textes einfügen. C++]]></title><description><![CDATA[<p>Hallo ich muss einen Text in einen anderen Text einfügen.<br />
So in etwa:</p>
<p>Text1</p>
<blockquote>
<p>blabla<br />
blabla<br />
/#ein#<br />
/#aus#<br />
blabla<br />
blabla</p>
</blockquote>
<p>Text2</p>
<blockquote>
<p>Braa<br />
Braa</p>
</blockquote>
<p>Text 2 muss zwischen /#ein# und /#aus# gebracht werden.<br />
Wie kann ich das am besten Programmieren ?</p>
<p>Ich möchte noch daraufhinweisen das ich nur ein bisschen C++ Erfahrung habe.</p>
<p>Danke im voraus.</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/313950/text-in-einem-bestimmten-abschnitt-eines-anderen-textes-einfügen-c</link><generator>RSS for Node</generator><lastBuildDate>Wed, 29 Jul 2026 17:25:04 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/313950.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 15 Feb 2013 08:41:55 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Text in einem bestimmten Abschnitt eines anderen Textes einfügen. C++ on Fri, 15 Feb 2013 08:43:05 GMT]]></title><description><![CDATA[<p>Hallo ich muss einen Text in einen anderen Text einfügen.<br />
So in etwa:</p>
<p>Text1</p>
<blockquote>
<p>blabla<br />
blabla<br />
/#ein#<br />
/#aus#<br />
blabla<br />
blabla</p>
</blockquote>
<p>Text2</p>
<blockquote>
<p>Braa<br />
Braa</p>
</blockquote>
<p>Text 2 muss zwischen /#ein# und /#aus# gebracht werden.<br />
Wie kann ich das am besten Programmieren ?</p>
<p>Ich möchte noch daraufhinweisen das ich nur ein bisschen C++ Erfahrung habe.</p>
<p>Danke im voraus.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2299007</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2299007</guid><dc:creator><![CDATA[MarvinH]]></dc:creator><pubDate>Fri, 15 Feb 2013 08:43:05 GMT</pubDate></item><item><title><![CDATA[Reply to Text in einem bestimmten Abschnitt eines anderen Textes einfügen. C++ on Fri, 15 Feb 2013 08:47:09 GMT]]></title><description><![CDATA[<p>Indem du Text1 einliest, dann Text2 einliest und dein Zeugs ausgibst, zwischendurch aber halt deine Texte ausgibst.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2299008</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2299008</guid><dc:creator><![CDATA[Skym0sh0]]></dc:creator><pubDate>Fri, 15 Feb 2013 08:47:09 GMT</pubDate></item><item><title><![CDATA[Reply to Text in einem bestimmten Abschnitt eines anderen Textes einfügen. C++ on Fri, 15 Feb 2013 08:59:58 GMT]]></title><description><![CDATA[<p>Hast du beide Texte in <code>std::string</code> gespeichert?<br />
Dann einfach mit der Memberfunktion <a href="http://www.cplusplus.com/reference/string/string/insert/" rel="nofollow">insert</a> und <a href="http://www.cplusplus.com/reference/string/string/find/" rel="nofollow">find</a> (mit newline).</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2299011</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2299011</guid><dc:creator><![CDATA[Sone]]></dc:creator><pubDate>Fri, 15 Feb 2013 08:59:58 GMT</pubDate></item><item><title><![CDATA[Reply to Text in einem bestimmten Abschnitt eines anderen Textes einfügen. C++ on Sun, 17 Feb 2013 15:01:58 GMT]]></title><description><![CDATA[<p>Ich habe jetzt gesucht und gegoogelt und habe dann diesen Code hier gefunden.</p>
<p>Jetzt muss ich noch mit find() basteln … geht das auch mit einem char array ?.<br />
(wie gesagt ich bin Anfänger <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f603.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--grinning_face_with_big_eyes"
      title=":D"
      alt="😃"
    /> (Learning by Doing) )</p>
<pre><code>#include &lt;iostream&gt;
#include &lt;fstream&gt;

using namespace std;

int main (void)
{
	char line[25000];
	ifstream infile (&quot;test.txt&quot;, ios::in);

	if(!infile)
    {
		cout &lt;&lt; &quot;Fehler&quot; &lt;&lt; endl;

	}
	while (infile.getline (line, 25000))
	{

		cout &lt;&lt; line &lt;&lt; endl;
	}
	cout &lt;&lt; endl;

return 0;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2299460</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2299460</guid><dc:creator><![CDATA[MarvinH]]></dc:creator><pubDate>Sun, 17 Feb 2013 15:01:58 GMT</pubDate></item><item><title><![CDATA[Reply to Text in einem bestimmten Abschnitt eines anderen Textes einfügen. C++ on Sun, 17 Feb 2013 15:43:31 GMT]]></title><description><![CDATA[<pre><code>#include &lt;fstream&gt;
#include &lt;iterator&gt;
#include &lt;string&gt;

int main()
{
    // Einlesen
    std::istream_iterator&lt;char&gt; end_of_file;

    std::ifstream file1(&quot;file1.txt&quot;);
    std::string text1(std::istream_iterator&lt;char&gt;(file1), end_of_file);

    std::ifstream file2(&quot;file2.txt&quot;);
    std::string text2(std::istream_iterator&lt;char&gt;(file2), end_of_file);

    // Stelle finden
    std::size_t insert_at = text1.find(&quot;something&quot;);

    // Einfügen
    text1.insert(insert_at, text2);

    return 0;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2299475</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2299475</guid><dc:creator><![CDATA[Nathan]]></dc:creator><pubDate>Sun, 17 Feb 2013 15:43:31 GMT</pubDate></item><item><title><![CDATA[Reply to Text in einem bestimmten Abschnitt eines anderen Textes einfügen. C++ on Sun, 17 Feb 2013 19:00:52 GMT]]></title><description><![CDATA[<p>Danke schön <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="🙂"
    /></p>
<p>Nachdem ich dem Code berarbeitet habe , kommt das wenn ich es ausführe… (Linux - Ubuntu 12.04 64Bit) :</p>
<pre><code>terminate called after throwing an instance of 'std::out_of_range'
  what():  basic_string::insert
Abgebrochen (Speicherabzug geschrieben
</code></pre>
<pre><code>#include &lt;fstream&gt; 
#include &lt;iterator&gt; 
#include &lt;string&gt; 
#include &lt;iostream&gt;
using namespace std;

int main() 
{ 
    // Einlesen 
    istream_iterator&lt;char&gt; end_of_file; 

    ifstream file1(&quot;file1.txt&quot;); 
    string text1(istream_iterator&lt;char&gt;(file1), end_of_file); 

    ifstream file2(&quot;file2.txt&quot;); 
    string text2(istream_iterator&lt;char&gt;(file2), end_of_file); 

    // Stelle finden 
    size_t insert_at = text1.find(&quot;2&quot;); 

    // Einfügen 
    text1.insert(insert_at, text2); 

    //ausgeben
    cout &lt;&lt; &quot;Ausgabetext&gt;\n&quot; &lt;&lt; text1 &lt;&lt; endl;

    fstream ausgabe;
    ausgabe.open(&quot;test-aus.txt&quot;, ios::out);
    ausgabe &lt;&lt; text1 &lt;&lt; endl;
    ausgabe.close();

    return 0; 
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2299539</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2299539</guid><dc:creator><![CDATA[MarvinH]]></dc:creator><pubDate>Sun, 17 Feb 2013 19:00:52 GMT</pubDate></item><item><title><![CDATA[Reply to Text in einem bestimmten Abschnitt eines anderen Textes einfügen. C++ on Sun, 17 Feb 2013 19:12:34 GMT]]></title><description><![CDATA[<p>Überprüfen mal insert_at auf std::string::npos.<br />
Das wird gesetzt, wenn das nicht gefunden wird.<br />
Generell könntest du auch die ifstreams überprüfen.<br />
Man öffnet Dateien übrigens im Ktor und lässt sie vom Dtor schließen, nutzte nicht manuell .close(), außer du willst die Datei erneut öffnen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2299541</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2299541</guid><dc:creator><![CDATA[Nathan]]></dc:creator><pubDate>Sun, 17 Feb 2013 19:12:34 GMT</pubDate></item><item><title><![CDATA[Reply to Text in einem bestimmten Abschnitt eines anderen Textes einfügen. C++ on Sun, 24 Mar 2013 12:31:38 GMT]]></title><description><![CDATA[<p>Nathan schrieb:</p>
<blockquote>
<pre><code>#include &lt;fstream&gt;
#include &lt;iterator&gt;
#include &lt;string&gt;

int main()
{
    // Einlesen
    std::istream_iterator&lt;char&gt; end_of_file;

    std::ifstream file1(&quot;file1.txt&quot;);
    std::string text1(std::istream_iterator&lt;char&gt;(file1), end_of_file);

    std::ifstream file2(&quot;file2.txt&quot;);
    std::string text2(std::istream_iterator&lt;char&gt;(file2), end_of_file);

    // Stelle finden
    std::size_t insert_at = text1.find(&quot;something&quot;);

    // Einfügen
    text1.insert(insert_at, text2);

    return 0;
}
</code></pre>
</blockquote>
<p>Hier werden die Zeilenumbrüche nicht berücksichtigt.<br />
Das liegt anscheinend an dem ifstream?!</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2309276</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2309276</guid><dc:creator><![CDATA[MarvinH]]></dc:creator><pubDate>Sun, 24 Mar 2013 12:31:38 GMT</pubDate></item><item><title><![CDATA[Reply to Text in einem bestimmten Abschnitt eines anderen Textes einfügen. C++ on Sun, 24 Mar 2013 12:42:49 GMT]]></title><description><![CDATA[<pre><code>int main()
{
    // Einlesen
    std::istream_iterator&lt;char&gt; end_of_file;

    std::ifstream file1(&quot;file1.txt&quot;);
	std::string text1(std::istream_iterator&lt;char&gt;(file1&gt;&gt;std::noskipws), end_of_file);

    std::ifstream file2(&quot;file2.txt&quot;);
    std::string text2(std::istream_iterator&lt;char&gt;(file2&gt;&gt;std::noskipws), end_of_file);

    // Stelle finden
    std::size_t insert_at = text1.find(&quot;something&quot;);

    // Einfügen
    text1.insert(insert_at, text2);

    return 0;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2309280</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2309280</guid><dc:creator><![CDATA[out]]></dc:creator><pubDate>Sun, 24 Mar 2013 12:42:49 GMT</pubDate></item><item><title><![CDATA[Reply to Text in einem bestimmten Abschnitt eines anderen Textes einfügen. C++ on Sun, 05 May 2013 12:44:34 GMT]]></title><description><![CDATA[<p>Nathan schrieb:</p>
<blockquote>
<p>Überprüfen mal insert_at auf std::string::npos.<br />
Das wird gesetzt, wenn das nicht gefunden wird.</p>
</blockquote>
<p>Wie schaffe ich das denn ?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2321127</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2321127</guid><dc:creator><![CDATA[MarvinH]]></dc:creator><pubDate>Sun, 05 May 2013 12:44:34 GMT</pubDate></item><item><title><![CDATA[Reply to Text in einem bestimmten Abschnitt eines anderen Textes einfügen. C++ on Sun, 05 May 2013 12:47:45 GMT]]></title><description><![CDATA[<p>MarvinH schrieb:</p>
<blockquote>
<p>Nathan schrieb:</p>
<blockquote>
<p>Überprüfen mal insert_at auf std::string::npos.<br />
Das wird gesetzt, wenn das nicht gefunden wird.</p>
</blockquote>
<p>Wie schaffe ich das denn ?</p>
</blockquote>
<p><code>insert_at != std::string::npos</code></p>
]]></description><link>https://www.c-plusplus.net/forum/post/2321128</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2321128</guid><dc:creator><![CDATA[out]]></dc:creator><pubDate>Sun, 05 May 2013 12:47:45 GMT</pubDate></item><item><title><![CDATA[Reply to Text in einem bestimmten Abschnitt eines anderen Textes einfügen. C++ on Sun, 05 May 2013 12:48:48 GMT]]></title><description><![CDATA[<p>MarvinH schrieb:</p>
<blockquote>
<p>Nathan schrieb:</p>
<blockquote>
<p>Überprüfen mal insert_at auf std::string::npos.<br />
Das wird gesetzt, wenn das nicht gefunden wird.</p>
</blockquote>
<p>Wie schaffe ich das denn ?</p>
</blockquote>
<p>Ein Vergleich? <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f62e.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--face_with_open_mouth"
      title=":open_mouth:"
      alt="😮"
    /> <code>insert_at == std::string::npos</code> .</p>
<p>Sieh auch die Dokumentation zu<a href="http://en.cppreference.com/w/cpp/string/basic_string/find" rel="nofollow"> <code>std::basic_string&lt;&gt;::find</code> </a>.</p>
<p>Edit: Bzw. auf Ungleichheit prüfen, je nach dem.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2321129</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2321129</guid><dc:creator><![CDATA[Sone]]></dc:creator><pubDate>Sun, 05 May 2013 12:48:48 GMT</pubDate></item><item><title><![CDATA[Reply to Text in einem bestimmten Abschnitt eines anderen Textes einfügen. C++ on Sat, 11 May 2013 17:33:36 GMT]]></title><description><![CDATA[<p>… aber npos gibt doch die maximale länge von size_type an.</p>
<p>Wieso sollte ich das dann mit dem Pointer &quot;insert_at&quot; vergleichen ?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2322682</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2322682</guid><dc:creator><![CDATA[MarvinH]]></dc:creator><pubDate>Sat, 11 May 2013 17:33:36 GMT</pubDate></item><item><title><![CDATA[Reply to Text in einem bestimmten Abschnitt eines anderen Textes einfügen. C++ on Sat, 11 May 2013 17:36:45 GMT]]></title><description><![CDATA[<p>MarvinH schrieb:</p>
<blockquote>
<p>… aber npos gibt doch die maximale länge von size_type an.</p>
<p>Wieso sollte ich das dann mit dem Pointer &quot;insert_at&quot; vergleichen ?</p>
</blockquote>
<p>Lies bitte die Dokumentation. Du machst es schwer uns zu helfen, wenn du nicht auf uns hörst.<br />
Der Rückgabewert von <code>string::find</code> ist kein Zeiger, sondern - falls das Zeichen gefunden wurde - die Position, sonst <code>std::string::npos</code> .</p>
<p>Das hätte dir aber eben auch die Referenz verraten.</p>
<blockquote>
<p>Return value: position of the first character of the found substring or npos if no such substring is found.</p>
</blockquote>
]]></description><link>https://www.c-plusplus.net/forum/post/2322683</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2322683</guid><dc:creator><![CDATA[Sone]]></dc:creator><pubDate>Sat, 11 May 2013 17:36:45 GMT</pubDate></item><item><title><![CDATA[Reply to Text in einem bestimmten Abschnitt eines anderen Textes einfügen. C++ on Sat, 11 May 2013 18:28:20 GMT]]></title><description><![CDATA[<p>Sone schrieb:</p>
<blockquote>
<p>MarvinH schrieb:</p>
<blockquote>
<p>… aber npos gibt doch die maximale länge von size_type an.</p>
<p>Wieso sollte ich das dann mit dem Pointer &quot;insert_at&quot; vergleichen ?</p>
</blockquote>
<p>Lies bitte die Dokumentation. Du machst es schwer uns zu helfen, wenn du nicht auf uns hörst.<br />
Der Rückgabewert von <code>string::find</code> ist kein Zeiger, sondern - falls das Zeichen gefunden wurde - die Position, sonst <code>std::string::npos</code> .</p>
<p>Das hätte dir aber eben auch die Referenz verraten.</p>
<blockquote>
<p>Return value: position of the first character of the found substring or npos if no such substring is found.</p>
</blockquote>
</blockquote>
<p>Ohh danke … ich habe den Fehler gefunden.</p>
<p>Der Marker … also das was gefunden werden soll , war nicht vorhanden … deswegen gab es diese Fehlermeldung.</p>
<p>Ich danke für die mühen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2322695</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2322695</guid><dc:creator><![CDATA[MarvinH]]></dc:creator><pubDate>Sat, 11 May 2013 18:28:20 GMT</pubDate></item></channel></rss>