如何从 n 个字符串中查找子字符串
How to find sub string from n strings
我正在尝试制作一个具有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;
}
}
}
}
我把!!放在哪里,我不知道如何编码那部分。
只是为了回答你的问题:以下行应该可以完成这项工作:
if(first.find(temp) != std::string::npos)
相关文章:
- 使用正则表达式regex_search在字符串中查找字符串
- 按类型与字符串查找对象
- 使用C RTTI(内置)通过字符串查找功能指针
- 关于获取行和字符串查找函数的问题
- 字符串查找方法找不到第一字母
- C++ 字符串.查找()
- 遇到字符串::查找的问题
- 将一个数组作为子字符串查找到另一个数组中
- 字符串查找第一个非的 C++ 问题
- 如何将通配符与字符串::查找一起使用
- 字符串::查找问题 (C++)
- 性能标准::strstr vs. 标准::字符串::查找
- C++字符串::查找崩溃应用程序
- 使用字符串查找单词的正确方法是什么
- 如何在<string>没有 std::string 中介的情况下制作一个支持通过 C 字符串查找的集合?
- 使用C++根据行中的第一个字符串查找行(仅一个)
- Borland字符串::查找bug
- std::map如何通过字符串查找元素
- 字符串查找函数返回奇数
- 如何使用子字符串查找数字行的正确部分