btw in your code, you put count = 0 INSIDE the for loop, which means no matter how many times you find a match and do count ++, it will always iterate back to 0
I've tested it with the change I suggested, and I can verify that it will work.
'count' needs to be set back to zero after every loop iteration. What he's doing is making 'ret' false if count is never incremented during the inside loop. But 'count' needs to count fresh for each character in stirngB
so you're saying to put count=0; inside the first for loop but AFTER the second for loop?
Both of you two are showing me two different ways.
Alex, the reason why your code wouldn't work for this is because if the tables were turned and string - a was pinneapple and string - b was line, then there would count would be == 5. Which is != b.size() in this case.
Just got it Jayhawk... I thought I had it say (count > 0). So dumb.. Literally one simple mistake and the whole code doesn't work. I just got it working. Even with the count=0 still inside the first for loop.
int main()
{
bool found = false;
std::string stringsA[] = { "teststring1", "pineapple", "turtle", "imbadatmakingexamples" };
std::string stringsB[] = { "test", "linen", "purple", "makebats" };
for (auto i = 0; i < 4; i++)
{
found = hasEach2(stringsA[i], stringsB[i]);
std::cout << "Iteration One: " << found << " | " << stringsA[i] << (found ? "' has '" : "' does not have '") << stringsB[i] << "'" << std::endl;
}
}
Produces
Iteration One: 1 | teststring1' has 'test'
Iteration One: 1 | pineapple' has 'linen'
Iteration One: 0 | turtle' does not have 'purple'
Iteration One: 1 | imbadatmakingexamples' has 'makebats'
Press any key to continue . . .
You can use that for lots of tests really fast. But now you know that it works :P
Welcome to the world of programming. Little errors like that are actually very common.