我想檢查一個字符串數組中的每個字符串是否等於五個元音中的任何一個。但是,當我測試它來查看字符串中的元音字符是否等於'元音'時,我知道它們不相等。代碼的問題是下面的粗體部分。此外,當我嘗試做「一個」|| 「e」|| 「我」|| 「o」|| 「u」,我得到ISO C++禁止指針和整數之間比較的錯誤。我如何能夠檢查它們是否相同?感謝您的時間。爲什麼字符串的每個單個字符都不等於字符對等?
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <cmath>
#include <cstdlib>
using namespace std;
int l, c; //l is amount of letters in password, c is amount of letters being inputted
char letters[1000000]; //the letters being inputted
vector <string> pass; //string vector of the stored passwords
void rec(string current, int index, int x){ //determining all possible passwords
if (index >= 4){
pass.push_back(current);
}
else{
for (int i=0; i<c; i++){
if (x<i){
int old;
old = x;
x = i;
rec(current + letters[i], index+1, x);
x = old;
}
}
}
}
int main (int argc, char ** argv)
{
cin >> l >> c;
int x = -1;
for (int i=0; i<c ;i++){
cin >> letters[i];
}
sort(letters, letters + c); //sorted from least to greatest
rec("", 0, x);
for (int i=0; i<pass.size(); i++){
int vl=0; //number of vowels
int nvl=0; //number of non-vowels (consonants)
for (int j=0; j<l; j++){
**if (pass.at(0)[j] == 'a' || pass.at(0)[j] =='e' || pass.at(0)[j] =='i' || pass.at(0)[j] =='o' || pass.at(0)[j] =='u'){**
vl++;
}
else{
nvl++;
}
if (j == l-1){
if (vl >= 1 && nvl >= 2){
cout << pass.at(0) << endl;
}
}
}
}
return 0;
}
代碼的「加粗」的部分是,有兩個星號的部分 – bobtheboy
看看if語句中有多個子句的其他例子。這個陳述正在做一些與你想要的不同的事情。 – jonsca