Einzelnen Beitrag anzeigen

boserPascal

Registriert seit: 4. Apr 2006
96 Beiträge
 
Delphi 5 Professional
 
#2

Re: [C++] String vergleichen

  Alt 19. Sep 2007, 16:32
Da du ja mit C Strings arbeitest, kannst du dich hier ja mal umschauen :
http://cppreference.com/stdstring/index.html

In C++ würde ich aber eher so arbeiten.

Code:
#include <string>

int anzahl(const char * sb, const char * str)
{
   std::string text(str);
   std::string::size_type stelle = text.find(sb);
   int result = 0;
   while(stelle != std::string::npos)
   {
      result++;
      stelle = text.find(sb, stelle+1);
   }
   return result;
}
Edit:
Was man alles für Fehler macht, wenn der Compiler nicht prüft
Stefan
  Mit Zitat antworten Zitat