显示没有与运算符&&相匹配的内容

时间:2019-10-20 16:13:18

标签: c++

#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}' )请帮我解决这个问题

1 个答案:

答案 0 :(得分:0)

您的代码中有一些错误。我帮你修好了 您错过了第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;
    }
}