C++ Error: 'no match for operator<…'

房东的猫 提交于 2019-12-13 11:18:32

问题


I have been attempting to create a password generator. The program is supposed to take input, and put out every possible combo of characters (brute force without the force). I am encountering this error: error: no match for 'operator<=' in 'i <= pear'

I have no idea what to do. However, here is the code. Please let me know if I also messed up on anything else, but the error described is the main problem right now:

#include <iostream>
#include <string>

using namespace std;

void generate() {
    int i=0;
    string pass;
    string r;
    string pear;
    for(i=0; i <= pear; i++) {
        pear = pass;
            r = pass[i];
}


    return r;
}

int main() {
    int i;
    string apple;
    cin >> apple;
    generate(apple,i);
    cout << apple;
}

回答1:


//...    
generate(apple,i);
//...

you have to specify the arguments in the signature of your function 'generate' like:

void generate( string apple, int it ) {

And the error:

size_t i;
//...
for(i=0; i <= pear.length(); i++) {
   //logic here?!
}

you add an element to a string using:

string.push_back( 'a' );


来源:https://stackoverflow.com/questions/32216172/c-error-no-match-for-operator

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!