void string_searching() { char text[14] = "It's a pencil."; char pattern[6] = "a pen"; // 仔細估量枚舉範圍 for (int i=0; i<14-6+1; i++) { bool find = true; for (int j=0; j<5; j++) if (text[i+j] != pattern[j]) { find = false; break; } if (find) cout << "短字串出現在第" << i << "個字元"; } }