C ++错误:“运算符不匹配< ..." [英] C++ Error: 'no match for operator<...'

查看:162
本文介绍了C ++错误:“运算符不匹配< ..."的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试创建密码生成器.该程序应该接受输入,并输出所有可能的字符组合(强力而不强力).我遇到此错误:错误:"i< = pear"中"operator< ="不匹配

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;
}

推荐答案

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

您必须在函数'generate'的签名中指定参数,例如:

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

void generate( string apple, int it ) {

错误:

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

您可以使用以下方法将元素添加到字符串中:

you add an element to a string using:

string.push_back( 'a' );

这篇关于C ++错误:“运算符不匹配&lt; ..."的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆