我正在尝试创建一个包含N个数组的程序,这些数组搜索两个字符串的匹配字符,然后将子字符串与其余字符串进行比较。这是代码:
int main ()
{
int a, b, n;
char sir[50];
printf("Number of strings: "); scanf("%d", &n);
if(n<=1){
printf("The program cannot run without at least 2 strings!");
} else {
printf("The program will run for %d strings.\n", n);
printf("\nString number 1: ");
scanf("%s", &sir);
std::string first(sir);
cout << first;
for(a=2; a<=n; ){
printf("\nString number %d: ", a);
scanf("%s", &sir);
std::string temp(sir);
if(!!!first.contains(temp)!!!){
a++;
} else {
printf("Program stops the substring doesn't match with the last string.");
return 0;
}
}
}
}
我把!!!放在哪里我不知道如何编写该部分。
答案 0 :(得分:0)
回答你的问题:以下一行应该完成这项工作:
if(first.find(temp) != std::string::npos)