字符串匹配有问题
程序代码:
#include<iostream> using namespace std; int main() { char a[]{"The string consisting of something."}; char b[]{"sting"}; int c[10]; int i{}, j{}, k{}; while (a[i]) { if (a[i] == 's') c[j] = i; i++; j++; } i = 0; for (auto k : c) { j = 0; for (i = k; i < k + 5; i++) { if (a[i] != b[j]) break; j++; } if (j == 5) cout << k; } return 0; }
调试看来从if语句开始有问题,求大神指点