2017-01-29 136 views
-3

我試圖用N個數組搜索兩個字符串的匹配字符,然後將子字符串與其餘字符串進行比較。這裏的代碼:如何從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

:以下行應該做的工作? –

+3

您遇到什麼問題?你的代碼在做什麼,你不期望它做什麼? –

+0

不知道如何使用std :: cout和std :: cin,xD我在開始.... – Cravenica

回答

0

只是爲了回答你的問題:你爲什麼不使用'的std :: cout`和'的std :: cin`

if(first.find(temp) != std::string::npos) 
相關問題