繁体   English   中英

没有运算符匹配|| 这些操作数

[英]no operator matches || these operands

嗨,我在C ++中使用if语句遇到麻烦。 编译代码时,出现错误,指出“没有运算符“ ||”与这些操作数匹配。 有什么猜想吗? 该项目是我在Visual Studio中创建的一款基于文本的小型游戏。

#include "stdafx.h"
#include <iostream>
#include <iomanip>
#include <string>
#include <cmath>
#include <fstream>

using namespace std;

//Prototypes
void introScreen(int);
string characterCreation(string);



int choice;
string characterName, wepon1, wepon2, bow, sword, mace;

const string sword = sword;
const string bow = bow;
const string mace = mace;

// Functions 

int main()
{
    introScreen(choice);

    return 0;
}


void introScreen(int choice)
{

    cout << "----------------------------------------\n"
        << "Welcome to the arena!\n"
        << "Select a menu option\n"
        << "-----------------------------------------\n"
        << "1. New Game\n"
        << "2. Load\n"
        << "3. Exit\n\n"
        << "Enter your desired number ";
    cin >> choice;

    if (choice == 1)
        characterCreation(characterName);
    else
        if (choice == 2)
            exit(0);
        else
            if (choice == 3)
                exit(1);

}


string characterCreation(string characterName,string wepon1,string wepon2, const string bow, const string sword, const string mace)
{

    cout << "Welcome to the character creation menu!\n"
        << "Enter your name\n"
        << "Name: ";
    cin.ignore();
    getline(cin, characterName);

    ofstream loadFile("Save.txt");
    loadFile << characterName << endl;

    cout << "\nEnter 2 wepons\n"
        << "Wepon list\n\n"
        << "Sword\n"
        << "Mace\n"
        << "Bow\n";
    cin >> wepon1, wepon2;

    if (wepon1 || wepon2 != bow || sword || mace)
    {
        cout << "\n\nThose wepons are invalid! Enter new ones\n";
        cout << "\nEnter 2 wepons\n"
            << "Wepon list\n\n"
            << "sword\n"
            << "mace\n"
            << "bow\n";
        cin >> wepon1, wepon2;
    }

    loadFile << wepon1 << endl
        << wepon2 << endl;


    return characerName;
}

“ ||” 运算符是对逻辑条件的评估,您正在要求它评估字符串类型。 通常,在评估字符串值时,它们的评估方式就好像(weapon1!=“”)然后...

另外,请注意如何设置该值。 字符串值在双引号内传递。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM