我米試圖遍歷串的矢量,和在所述字符串的每一個字符:迭代向量串的字符(C++禁止指針和整數之間的比較)
但我得到一個錯誤:C++禁止比較指針和整數之間。
In member function ‘int LetterStrings::sum(std::vector<std::basic_string<char> >)’:
error: ISO C++ forbids comparison between pointer and integer [-fpermissive]|
以下是我的代碼:
#include<iostream>
#include<vector>
#include<typeinfo>
#include<string>
using namespace std;
class LetterStrings {
public:
int sum(vector <string> s) {
int i, j = 0;
int count = 0;
for(i=0;i<s.size();i++) {
for(j=0;j<s[i].length();j++) {
if(s[i][j] != "-") {
count ++;
}
}
}
return count;
}
};
有人可以告訴我,什麼是錯我的代碼。
**我真的很陌生的C++。
試一下[i] [j]!='-'' –