所以我有了这个,如果我注释掉底部, from int count = 0;
toreturn 0;
它会打印出来,但在这种情况下,什么都不会打印出来。即使cout << "Test"
在开始时添加也无济于事。这一切都编译得很好。
#include <iostream>
#include <string>
#include <cctype>
using namespace std;
int main()
{
string text = "Smith, where Jones had had \"had had\", had had \"had\". \"Had had\" had had the examiners' approval.";
string search = "had";
int length = (int) text.length();
for(int i = 0; i < length; i++)
{
text [i] = tolower(text [i]);
}
cout << text;
int count = 0;
for (int index = 0; (index = text.find(search)) != string::npos; index += search.length()) {
count++;
}
cout << "There are " << count << " occurences of \"" << search << "\".\n";
return 0;
}