This is more or less what i had in mind:
unsigned int count = 0;
std::size_t found = str.find("gc");
while(found != std::string::npos)
{
found = str.find("gc", found + 2);
++count;
Type: Posts; User: Neo1
This is more or less what i had in mind:
unsigned int count = 0;
std::size_t found = str.find("gc");
while(found != std::string::npos)
{
found = str.find("gc", found + 2);
++count;
Yes i suppose it could seem slightly counterintuitive to use find like this. If you were just looking for a simple value i would suggest std::count but since you are actually looking for a sequence...
You need a closing bracket '}' on line 32 and line 25 in the code i posted. Without these the program will not do as you intend.
Also as i mentioned earlier, you're indexing your string one past...
#include <iostream>
#include <string>
using namespace std;
int main ()
{
string input;
So the first thing i will mention is your indentation, it is very inconsistent. As a result of this, you have a bunch of mismatched brackets, they are all over the place. Fix your indentation and you...