#include <iostream> #include <string> using namespace std; int main() { int coun
ID: 3640829 • Letter: #
Question
#include <iostream>#include <string>
using namespace std;
int main()
{
int count = 0;
int occur = 0;
string string1, string2;
// Input string1
cout << "Please enter a string." << endl;
getline(cin,string1);
cout << "The string you entered was: " << string1 << endl;
// Input string2
cout << "Please enter a substring to search within the first string." << endl;
getline (cin, string2);
cout << "The substring you entered was: " << string2 << endl;
cout << "The substring occurs " << count << " times within the string.";
occur = string1.find(string2, occur);
while (occur >= 0)
{
occur +=string2.length();
count += 1;
occur = string1.find(string2, occur);
return count;
}
return 0;
}
Explanation / Answer
http://codepad.org/E1gHifSA Didnt want to have spacing all messed up but here ya go. You were not really doing anything. I know you might have thought you made a method with occur, but really it didnt do anything. If you want anything more explained dont hesitate to ask.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.