簡體   English   中英

'const char [2]'類型的值不能隱式轉換為'int'ERROR C ++

[英]Value of type 'const char[2]' is not implicitly convertible to 'int' ERROR C++

我正在編寫一個快速程序來重新熟悉C ++,但是我的開關上出現了標題錯誤(選擇){case“A”:break;}行。

[類型'const char [2]'的值不能隱式轉換為'int']

如果有人能幫助我理解為什么我會得到這個錯誤以及如何糾正它,將不勝感激。 謝謝!

錯誤圖片: http//imgur.com/a/d2A0P

#include <iostream>
#include <vector>
#include <string>
#include <fstream>
#include <cstdlib>

using namespace std;

char printMenuChoice(char choice);

void printSpace(){
    cout << endl;
}

int main(){
    //Print Menu Choice
    char choice;
    choice = printMenuChoice(choice);
    cout << "Choice is " << choice << endl;
    switch(choice){
        case "A":

            break;
    }
    //Attack
    //Chop
    //Shop
    //Stats
    //Exit
}

char printMenuChoice(char choice){
    cout << "[]--- Welcome to Quick Quests ---[]" << endl;
    printSpace();
    cout << "Attack <A>" << endl;
    cout << "Chop   <B>" << endl;
    cout << "Shop   <C>" << endl;
    cout << "Exit   <E>" << endl;
    printSpace();
    cout << "Input Your Choice: ";

    printSpace();
    cin >> choice;
    choice = toupper(choice);
    return choice;
}

您正在使用char* (字符串)文字而不是char文字。 case 'A':相反。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM