簡體   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