首页 > 解决方案 > 它显示与 operator&& 不匹配

问题描述

#include < cstdio>

#include < cstdlib>

#include < iostream>

#include < string>

using namespace std;

int main ( int nNumberofArgs, char* pszArgs[])

{

    string name;

    string password;

    int ans1;

    printf("Turn on the BEDrive??\n(write an ODD number for 'no' and EVEN 'yes'\n");

    cin >> ans1;



     while(ans1%2==0)

    {
        printf("Hello Master... Welcome to the BEDrive System...\nwould you like to login...\n);


        cin.ignore(10, '\n');

        cin.get();

        printf("Enter your login ID: ");

        cin >> name;

        printf("Enter your password: ");

        cin >> password;

        if(name = "smartyguy1" && password = "Bhanuhanu1")

        {

            printf("WELCOME MASTER!!!!.\nDo you want to change your password(y/n)?");

        }

        else

        {

            printf("Login FAILED!!!:( ");

        }


        return 0;
    }
}

当我编译这段代码时,它显示错误:不匹配'operator&&'(操作数类型是'const char [11]'和'std::__cxx11::string {aka std::__cxx11::basic_string}')请帮助我用这个

标签: c++

解决方案


您的代码中有一些错误。我为你修好了。你错过了第 30 行的结尾 "。

#include <cstdio> // "< cstdio>" is not correct, no space is allowed here

#include <cstdlib>

#include <iostream>

#include <string>

using namespace std;

int main ( int nNumberofArgs, char* pszArgs[])

{

    string name;

    string password;

    int ans1;

    printf("Turn on the BEDrive??\n(write an ODD number for 'no' and EVEN 'yes'\n");

    cin >> ans1;



     while(ans1%2==0)

    {
        printf("Hello Master... Welcome to the BEDrive System...\nwould you like to login...\n"); // you missed ending " here


        cin.ignore(10, '\n');

        cin.get();

        printf("Enter your login ID: ");

        cin >> name;

        printf("Enter your password: ");

        cin >> password;

        if(name == "smartyguy1" && password == "Bhanuhanu1")

        {

            printf("WELCOME MASTER!!!!.\nDo you want to change your password(y/n)?");

        }

        else

        {

            printf("Login FAILED!!!:( ");

        }


        return 0;
    }
}

推荐阅读