<?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[Wie Anzahl ermitteln?]]></title><description><![CDATA[<p>Wie kann man die Anzahl eines in einer Datei mehrfach vorkommenden gleichlautendem Eintrags ermitteln?<br />
Ich hätte da an sowas wie replace und dann die Differenz zum Original Inhalt berechnen gedacht oder gibts da so eine Funktion, die das komplett machen kann?<br />
Danke im voraus!</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/184686/wie-anzahl-ermitteln</link><generator>RSS for Node</generator><lastBuildDate>Wed, 23 Sep 2026 23:56:47 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/184686.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 18 Jun 2007 08:48:46 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Wie Anzahl ermitteln? on Mon, 18 Jun 2007 08:48:46 GMT]]></title><description><![CDATA[<p>Wie kann man die Anzahl eines in einer Datei mehrfach vorkommenden gleichlautendem Eintrags ermitteln?<br />
Ich hätte da an sowas wie replace und dann die Differenz zum Original Inhalt berechnen gedacht oder gibts da so eine Funktion, die das komplett machen kann?<br />
Danke im voraus!</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1308217</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1308217</guid><dc:creator><![CDATA[dixidix]]></dc:creator><pubDate>Mon, 18 Jun 2007 08:48:46 GMT</pubDate></item><item><title><![CDATA[Reply to Wie Anzahl ermitteln? on Mon, 18 Jun 2007 08:50:44 GMT]]></title><description><![CDATA[<p>hä????</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1308219</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1308219</guid><dc:creator><![CDATA[BorisDieKlinge]]></dc:creator><pubDate>Mon, 18 Jun 2007 08:50:44 GMT</pubDate></item><item><title><![CDATA[Reply to Wie Anzahl ermitteln? on Mon, 18 Jun 2007 08:58:08 GMT]]></title><description><![CDATA[<p>Dachte es wäre klar, also nochmal zum mitschreiben.</p>
<p>Hch hab eine Datei mit dem (sinnlosem)Text:</p>
<pre><code>xxxx
jhasjdh
sjaf
kasjdfkjw
xxxx
kjdf
lwjkrfhlkwe
xxxx
lejkrek
xxxx
</code></pre>
<p>ich will einfach nur wissen wie oft da der String xxxx vorkommt.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1308222</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1308222</guid><dc:creator><![CDATA[dixidix]]></dc:creator><pubDate>Mon, 18 Jun 2007 08:58:08 GMT</pubDate></item><item><title><![CDATA[Reply to Wie Anzahl ermitteln? on Mon, 18 Jun 2007 08:59:40 GMT]]></title><description><![CDATA[<p>Hi,</p>
<p>auf Dateien selbst hat man gar keinen direkten Zugriff (mit Standard-C++). Man kann lediglich streams erzeugen, die mit ihnen verknüpft sind und dann auch diese Streams zugreifen.</p>
<p>Ergo:</p>
<ul>
<li>ifstream anlegen</li>
<li>zeichen-/string-/zeilenweise einlesen (je nachdem, was Du suchst: Identische Zeichen oder strings oder Zeilen),</li>
<li>vergleichen und</li>
<li>zählen.</li>
</ul>
<p>(Für das Zählen braucht man gar keinen verändernden Zugriff)<br />
Die Implementierung sei dem geneigen Programmierer als einfache Fingerübung überlassen.</p>
<p>Gruß,</p>
<p>Simon2.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1308223</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1308223</guid><dc:creator><![CDATA[Simon2]]></dc:creator><pubDate>Mon, 18 Jun 2007 08:59:40 GMT</pubDate></item><item><title><![CDATA[Reply to Wie Anzahl ermitteln? on Mon, 18 Jun 2007 09:21:37 GMT]]></title><description><![CDATA[<p>dixidix schrieb:</p>
<blockquote>
<p>ich will einfach nur wissen wie oft da der String xxxx vorkommt.</p>
</blockquote>
<p>Ich würde die gesamte Datei in einen Puffer einlesen und dann mit der Funktion memcmp() mir die Anzahl der Vorkommen holen in einer Schleife holen.</p>
<p>PS: memcmp() hat C++ von C geerbt.</p>
<p><img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f609.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--winking_face"
      title=";)"
      alt="😉"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1308235</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1308235</guid><dc:creator><![CDATA[emmax]]></dc:creator><pubDate>Mon, 18 Jun 2007 09:21:37 GMT</pubDate></item><item><title><![CDATA[Reply to Wie Anzahl ermitteln? on Mon, 18 Jun 2007 11:17:41 GMT]]></title><description><![CDATA[<p>emmax schrieb:</p>
<blockquote>
<p>dixidix schrieb:</p>
<blockquote>
<p>ich will einfach nur wissen wie oft da der String xxxx vorkommt.</p>
</blockquote>
<p>Ich würde die gesamte Datei in einen Puffer einlesen und dann mit der Funktion memcmp() mir die Anzahl der Vorkommen holen in einer Schleife holen.</p>
<p>PS: memcmp() hat C++ von C geerbt.</p>
<p><img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f609.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--winking_face"
      title=";)"
      alt="😉"
    /></p>
</blockquote>
<p>Ich würde eine Lösung für <em>sein Problem</em> vorschlagen. Wenn er schon weiß, dass er mit strings arbeiten will ... warum sollte er es dann nicht tun ? <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f609.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--winking_face"
      title=";)"
      alt="😉"
    /></p>
<p>Gruß,</p>
<p>Simon2.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1308303</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1308303</guid><dc:creator><![CDATA[Simon2]]></dc:creator><pubDate>Mon, 18 Jun 2007 11:17:41 GMT</pubDate></item><item><title><![CDATA[Reply to Wie Anzahl ermitteln? on Mon, 18 Jun 2007 12:36:53 GMT]]></title><description><![CDATA[<p>hmm ...</p>
<pre><code class="language-cpp">std::size_t count_occurrences_of(const std::string&amp; string, const std::string&amp; of)
{
    std::size_t count = 0;
    for (std::size_t pos = string.find(of); pos != std::string::npos; ++count);
    return count;
}

bool file_count_occurrences_of(const std::string&amp; filename, const std::string&amp; of, std::size_t&amp; count)
{
    std::ifstream file_stream(filename.c_str(), std::ios::in);
    if (!file_stream)
        return false;

    std::string content;
    std::string line;
    while (std::getline(file_stream, line))
        content += line;

    count = count_occurrences_of(content, of);
    return true;
}
</code></pre>
<p><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>benutzen:</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;string&gt;

int main()
{
    std::cout &lt;&lt; &quot;Dateiname: &quot; &lt;&lt; std::flush;
    std::string filename;
    std::getline(std::cin, filename);
    std::cout &lt;&lt; &quot;Suchwort: &quot; &lt;&lt; std::flush;
    std::string search;
    std::getline(std::cin, search);
    std::size_t count = 0;
    if (file_count_occurrences_of(filename, search, count) == false)
    {
        std::cerr &lt;&lt; &quot;Datei konnte nicht geöffnet werden!&quot; &lt;&lt; std::endl;
        return 1;
    }
    std::cout &lt;&lt; &quot;\&quot;&quot; &lt;&lt; search &lt;&lt; &quot;\&quot; wurde &quot; &lt;&lt; count &lt;&lt; &quot;x in der Datei \&quot;&quot; &lt;&lt; filename &lt;&lt; &quot;\&quot; gefunden!&quot; &lt;&lt; std::endl;
}
</code></pre>
<p>wo war jetzt das Problem bei der Aufgabe?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1308368</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1308368</guid><dc:creator><![CDATA[*D*Evil]]></dc:creator><pubDate>Mon, 18 Jun 2007 12:36:53 GMT</pubDate></item><item><title><![CDATA[Reply to Wie Anzahl ermitteln? on Mon, 18 Jun 2007 12:53:47 GMT]]></title><description><![CDATA[<p>(D)Evil schrieb:</p>
<blockquote>
<p>...wo war jetzt das Problem bei der Aufgabe?</p>
</blockquote>
<p>Ich würde mal sagen in der Ungenauigkeit der Aufgabenstellung:<br />
+ Sollen die Zeilen genau so aussehen ? (also inkl. whitespaces)<br />
+ Was, wenn der gesuchte String mehrfach oder mitten in einem anderen auftritt ?<br />
+ ...</p>
<p>Deine Lösung hat bestimmte Eigenschaften (z.B. zählt er auch &quot;Umgebrochenes&quot; mit), bei denen nicht klar ist, ob der OP sie will - außerdem würd ich nicht erst den gesamten Dateiinhalt einlesen, wenn man das nicht braucht.</p>
<p>Würde nicht ein:</p>
<pre><code class="language-cpp">// return vs. throw Geschmackssache; hier nur als Alternative
count file_count_occurrences_of(const std::string&amp; filename, const std::string&amp; of)
{
    std::ifstream file_stream(filename.c_str()); // &quot;std::ios::in&quot; ist bestenfalls irreführend
    if (!file_stream) return throw std::runtime_error(&quot;unable to open infile&quot;);

    std::string line;
    std::size_t count=0;
    while (std::getline(file_stream, line))
        if(line == of) ++count

    return count;
}
</code></pre>
<p>reichen ?</p>
<p>BTW: Warum &quot;count_occurrences_of&quot;, wenn es doch std::count_if() gibt ? <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f609.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--winking_face"
      title=";)"
      alt="😉"
    /><br />
EDIT: Ach, jetzt war Werner doch ein wenig schneller....</p>
<p>Gruß,</p>
<p>Simon2.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1308379</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1308379</guid><dc:creator><![CDATA[Simon2]]></dc:creator><pubDate>Mon, 18 Jun 2007 12:53:47 GMT</pubDate></item><item><title><![CDATA[Reply to Wie Anzahl ermitteln? on Mon, 18 Jun 2007 12:51:25 GMT]]></title><description><![CDATA[<p>(D)Evil schrieb:</p>
<blockquote>
<p>wo war jetzt das Problem bei der Aufgabe?</p>
</blockquote>
<p>Das Problem liegt darin, die Aufgabe mit weniger Code unter Einsatz der C++-Bibliothek zu lösen. Das hatte dixidix wohl vergessen zu sagen.</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;fstream&gt;
#include &lt;string&gt;
#include &lt;algorithm&gt;    // count_if
#include &lt;iterator&gt;     // istream_iterator
#include &lt;functional&gt;   // bind2nd, equal_to

int main()
{
    using namespace std;
    ifstream datei( &quot;input.txt&quot; );
    cout &lt;&lt; &quot;Der Ausdruck 'xxxx' ist &quot; &lt;&lt; count_if( istream_iterator&lt; string &gt;( datei ), istream_iterator&lt; string &gt;(),
        bind2nd( equal_to&lt; string &gt;(), string(&quot;xxxx&quot;) ) ) &lt;&lt; &quot; mal enthalten&quot; &lt;&lt; endl;

    return 0;
}
</code></pre>
<p>queer_boy schrieb:</p>
<blockquote>
<p>kürzerer code ist meist aussagekräftiger.</p>
</blockquote>
<p>Gruß<br />
Werner</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1308381</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1308381</guid><dc:creator><![CDATA[Werner Salomon]]></dc:creator><pubDate>Mon, 18 Jun 2007 12:51:25 GMT</pubDate></item><item><title><![CDATA[Reply to Wie Anzahl ermitteln? on Tue, 19 Jun 2007 07:01:17 GMT]]></title><description><![CDATA[<p>Danke, mit soviel hatte ich garnicht gerechnet.<br />
Ich muss da aber noch mal was anhängen. Ginge das auch wenn der gesuchte String verschachtelt wäre, etwa so:</p>
<pre><code>hsdgxxxx
jhaxxxxsjdh
sjaf
kasjdfkjw
xxxxmsdgh
kjdf
lwjkrxxxxfhlkwe
grfadxxxx
lejkrek
xxxxashg
</code></pre>
<p>Mit den beiden letzten Funktionen kommt nur 0 als Rückgabe!</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1308818</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1308818</guid><dc:creator><![CDATA[dixidix]]></dc:creator><pubDate>Tue, 19 Jun 2007 07:01:17 GMT</pubDate></item><item><title><![CDATA[Reply to Wie Anzahl ermitteln? on Tue, 19 Jun 2007 07:09:31 GMT]]></title><description><![CDATA[<p>Ja, ginge auch, du müsstest nur eine andere Vergleichsfunktion an count_if() übergeben:</p>
<pre><code class="language-cpp">struct string_match
{
  string_match(const string&amp; data) : m_data(data) {}
  bool operator()(const string&amp; wert)
  { return wert.find(m_data) != string::npos; }
private:
  string m_data;
};

...
cout&lt;&lt;count_if(...,string_match(&quot;xxxx&quot;));
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1308823</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1308823</guid><dc:creator><![CDATA[CStoll]]></dc:creator><pubDate>Tue, 19 Jun 2007 07:09:31 GMT</pubDate></item><item><title><![CDATA[Reply to Wie Anzahl ermitteln? on Tue, 19 Jun 2007 07:55:41 GMT]]></title><description><![CDATA[<p>CStoll schrieb:</p>
<blockquote>
<p>Ja, ginge auch, du müsstest nur eine andere Vergleichsfunktion an count_if() übergeben</p>
</blockquote>
<p>Na,ja vor allen darf man keine std::string's also Worte, die durch Whitespace Chars von einander getrennt sind, einlesen. Wenn man den count_if beibehalten möchte, bedarf es einer eigenen Klasse, die solange Zeichenfolgen liest, bis was passendes daher kommt. Etwa so</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;fstream&gt;
#include &lt;string&gt;
#include &lt;algorithm&gt;    // count_if
#include &lt;iterator&gt;     // istream_iterator
#include &lt;functional&gt;   // bind2nd, equal_to

struct Zeichenfolge
{
    explicit Zeichenfolge( const std::string&amp; txt = std::string() ) : m_txt( txt ) {}
    bool operator==( const Zeichenfolge&amp; b ) const
    {
        return m_txt == b.m_txt;
    }
    friend std::istream&amp; operator&gt;&gt;( std::istream&amp; in, Zeichenfolge&amp; zf )
    {
        const std::ios_base::fmtflags oldFlags = in.flags();
        in &gt;&gt; std::noskipws;
        std::string txt;
        char c = 0;
        for( std::string::iterator iMuster = Zeichenfolge::m_muster.begin()
            ; iMuster != Zeichenfolge::m_muster.end() &amp;&amp; in &gt;&gt; c; ++iMuster )
        {
            txt.append( 1, c );
            if( c != *iMuster ) break;
        }
        in.flags( oldFlags );
        if( in ) swap( zf.m_txt, txt );
        return in;
    }
    static void SetMuster( const std::string&amp; muster ) { m_muster = muster; }

private:
    std::string m_txt;
    static std::string m_muster;
};
std::string Zeichenfolge::m_muster;

int main()
{
    using namespace std;
    const string muster = &quot;xxxx&quot;;
    ifstream datei( &quot;input.txt&quot; );
    Zeichenfolge::SetMuster( muster );
    cout &lt;&lt; &quot;Der Ausdruck '&quot; &lt;&lt; muster &lt;&lt; &quot;' ist &quot; &lt;&lt; count_if( istream_iterator&lt; Zeichenfolge &gt;( datei ), istream_iterator&lt; Zeichenfolge &gt;(),
        bind2nd( equal_to&lt; Zeichenfolge &gt;(), Zeichenfolge( muster ) ) ) &lt;&lt; &quot; mal enthalten&quot; &lt;&lt; endl;

    return 0;
}
</code></pre>
<p>Die Lösung über die statische Variable ist eigentlich nicht so toll; spätestens bei Multithreading funktioniert das nicht mehr. Schöner wäre es, den Muster-String via Manipulatoren und ios_base::pword an den istream zu hängen, aber das bläht den Code weiter auf.</p>
<p>Ich vermute aber mal, dass das ganze mit <a href="http://www.boost.org/libs/regex/doc/index.html" rel="nofollow">boost::regex</a> oder so einfacher zu lösen ist.</p>
<p>Gruß<br />
Werner</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1308839</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1308839</guid><dc:creator><![CDATA[Werner Salomon]]></dc:creator><pubDate>Tue, 19 Jun 2007 07:55:41 GMT</pubDate></item><item><title><![CDATA[Reply to Wie Anzahl ermitteln? on Tue, 19 Jun 2007 08:00:08 GMT]]></title><description><![CDATA[<p>dixidix schrieb:</p>
<blockquote>
<p>...Mit den beiden letzten Funktionen kommt nur 0 als Rückgabe!</p>
</blockquote>
<p>... was auch vollkommen klar ist, wen man den Code versteht. <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="😃"
    /></p>
<p>dixidix schrieb:</p>
<blockquote>
<p>...</p>
<pre><code>hsdgxxxx
jhaxxxxsjdh
sjaf
kasjdfkjw
xxxxmsdgh
kjdf
lwjkrxxxxfhlkwe
grfadxxxx
lejkrek
xxxxashg
</code></pre>
<p>...</p>
</blockquote>
<p>sollen eigentlich</p>
<pre><code>hsdgxxx
xjha
</code></pre>
<p>und</p>
<pre><code>x
  x
xx
</code></pre>
<p>auch mitgezählt werden ?</p>
<p>Das ist eben genau das, was ich meinte: Du musst für Dich klären, was genau Du möchtest - das ist eine fachliche Entscheidung. Keine der Varianten ist &quot;besser&quot; als die anderen, sondern höchstens &quot;passender&quot;.</p>
<p>Außerdem würde ich Dir raten, die verschiedenen hier angebotenen Lösungen mal genau zu studieren und zu versuchen sie zu verstehen - dann kannst Du es vielleicht noch &quot;passgenauer&quot; programmieren.</p>
<p>Gruß,</p>
<p>Simon2.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1308841</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1308841</guid><dc:creator><![CDATA[Simon2]]></dc:creator><pubDate>Tue, 19 Jun 2007 08:00:08 GMT</pubDate></item><item><title><![CDATA[Reply to Wie Anzahl ermitteln? on Tue, 19 Jun 2007 08:10:15 GMT]]></title><description><![CDATA[<p>So wie es jetzt ist also &quot;xxxx&quot; finden/zählen ist schon ok. Mir wäre sicher auch was eingefallen, aber sicher nicht so und anhand von solchen Beispielen lässt sich doch einiges besser nachvollziehen. Insofern wieder mal Danke!! <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f44d.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--thumbs_up"
      title=":+1:"
      alt="👍"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1308856</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1308856</guid><dc:creator><![CDATA[dixidix]]></dc:creator><pubDate>Tue, 19 Jun 2007 08:10:15 GMT</pubDate></item><item><title><![CDATA[Reply to Wie Anzahl ermitteln? on Tue, 19 Jun 2007 08:19:16 GMT]]></title><description><![CDATA[<p>Schade, ich habe gerade festgestellt, dass mein zuletzt geposteter Code nicht für beliebige Mustertexte funktioniert. Z.B. findet er den Ausdruck 'Hallo' in</p>
<blockquote>
<p>irgendwas HalHallo ..</p>
</blockquote>
<p>nicht. Lässt sich zwar reparieren, aber ich habe jetzt keine Zeit ...</p>
<p>Gruß<br />
Werner</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1308860</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1308860</guid><dc:creator><![CDATA[Werner Salomon]]></dc:creator><pubDate>Tue, 19 Jun 2007 08:19:16 GMT</pubDate></item><item><title><![CDATA[Reply to Wie Anzahl ermitteln? on Tue, 19 Jun 2007 11:34:53 GMT]]></title><description><![CDATA[<p>emmax schrieb:</p>
<blockquote>
<p>Ich würde die gesamte Datei in einen Puffer einlesen und dann mit der Funktion memcmp() mir die Anzahl der Vorkommen holen in einer Schleife holen.</p>
<p>PS: memcmp() hat C++ von C geerbt.<br />
<img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f609.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--winking_face"
      title=";)"
      alt="😉"
    /></p>
</blockquote>
<p>Hier mal mein Code</p>
<pre><code class="language-cpp">#include &lt;cstring&gt;
#include &lt;fstream&gt;
#include &lt;iostream&gt;

using namespace std; 

int main () 
{   
    ifstream file (&quot;input.txt&quot;,  ios::binary | ios::ate);  
    streamsize len = file.tellg ();
    char* buf = new char [len];
    file.seekg (0, ios::beg);
    file.read (buf, len);
    file.close ();

    const char muster[] = &quot;xxxx&quot;;
    int zähler = 0;

    for (streamsize i = 0; i &lt; len; i++)
    {
        if (!memcmp (buf+i, muster, (sizeof muster)-1))
        {
            zähler++;
            i += (sizeof muster)-2;
        }
    }

    delete[] buf;
    cout &lt;&lt; muster &lt;&lt; &quot; kommt &quot; &lt;&lt; zähler &lt;&lt; &quot; mal vor.&quot; &lt;&lt; endl;
}
 ;)
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1309031</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1309031</guid><dc:creator><![CDATA[emmax]]></dc:creator><pubDate>Tue, 19 Jun 2007 11:34:53 GMT</pubDate></item><item><title><![CDATA[Reply to Wie Anzahl ermitteln? on Tue, 19 Jun 2007 12:05:56 GMT]]></title><description><![CDATA[<p>dixidix schrieb:</p>
<blockquote>
<p>So wie es jetzt ist also &quot;xxxx&quot; finden/zählen ist schon ok. Mir wäre sicher auch was eingefallen, aber sicher nicht so und anhand von solchen Beispielen lässt sich doch einiges besser nachvollziehen. Insofern wieder mal Danke!! <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f44d.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--thumbs_up"
      title=":+1:"
      alt="👍"
    /></p>
</blockquote>
<p>Noch was: Was soll bei</p>
<pre><code>xxxxx
</code></pre>
<p>rauskommen ? 0, 1, 2 ?</p>
<p>Gruß,</p>
<p>Simon2.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1309072</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1309072</guid><dc:creator><![CDATA[Simon2]]></dc:creator><pubDate>Tue, 19 Jun 2007 12:05:56 GMT</pubDate></item><item><title><![CDATA[Reply to Wie Anzahl ermitteln? on Tue, 19 Jun 2007 12:33:27 GMT]]></title><description><![CDATA[<p>Simon2 schrieb:</p>
<blockquote>
<p>Noch was: Was soll bei</p>
<pre><code>xxxxx
</code></pre>
<p>rauskommen ? 0, 1, 2 ?</p>
<p>Gruß,</p>
<p>Simon2.</p>
</blockquote>
<p><strong>1</strong></p>
<pre><code class="language-cpp">...
            zähler++;
            i += (sizeof muster)-2;  // Lesen!
...
</code></pre>
<p><img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f609.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--winking_face"
      title=";)"
      alt="😉"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1309103</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1309103</guid><dc:creator><![CDATA[emmax]]></dc:creator><pubDate>Tue, 19 Jun 2007 12:33:27 GMT</pubDate></item><item><title><![CDATA[Reply to Wie Anzahl ermitteln? on Tue, 19 Jun 2007 12:54:06 GMT]]></title><description><![CDATA[<p>emmax schrieb:</p>
<blockquote>
<p>Simon2 schrieb:</p>
<blockquote>
<p>Noch was: Was soll bei</p>
<pre><code>xxxxx
</code></pre>
<p>rauskommen ? 0, 1, 2 ?</p>
<p>Gruß,</p>
<p>Simon2.</p>
</blockquote>
<p><strong>1</strong></p>
<pre><code class="language-cpp">...
            zähler++;
            i += (sizeof muster)-2;  // Lesen!
...
</code></pre>
<p><img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f609.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--winking_face"
      title=";)"
      alt="😉"
    /></p>
</blockquote>
<p>Du kannst die Frage danach, was <em>fachlich gewünscht</em> ist, nicht mit einer Eigenschaft <em>Deiner spezifischen Implementierung</em> beantworten.</p>
<p>Gruß,</p>
<p>Simon2.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1309128</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1309128</guid><dc:creator><![CDATA[Simon2]]></dc:creator><pubDate>Tue, 19 Jun 2007 12:54:06 GMT</pubDate></item><item><title><![CDATA[Reply to Wie Anzahl ermitteln? on Tue, 19 Jun 2007 21:10:52 GMT]]></title><description><![CDATA[<p>Öhm ... mein Code soll 0 zurückgeben? Oha ^^ Der macht es sogar möglich, dass der auch erkennt, wenn der Text in der nächsten Zeile weiter geht. Also er lässt das Newline außer acht.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1309452</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1309452</guid><dc:creator><![CDATA[*D*Evil]]></dc:creator><pubDate>Tue, 19 Jun 2007 21:10:52 GMT</pubDate></item></channel></rss>