簡體   English   中英

C ++ Basic while循環,帶擊鍵退出

[英]C++ Basic while loop with keystroke to exit

我是編程新手,這是我的第二個任務。 應該接受用戶的輸入,直到他們輸入| 退出程序。 我做錯了什么?

int main()

    int i = 0;
    char a = 0;
        while ( a != "|" ){  //has also told me this is an
                             // invalid operator
    int numeric;
    cout << "Give character: ";
    cin >> a ;
    cout << "Its ascii value is: " << (int) a << endl;
    ++i;

    }
}

這是錯誤:

2   IntelliSense: operand types are incompatible ("char" and "const char *")    

不要使用"|" '|' 代替。 您想將charchar比較, char要將charchar*

您應改用while ( a != '|' )

'|' 是字符和"|" 是只有1個字符的字符串

暫無
暫無

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

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