[英]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 *")
不要使用"|"
。 放'|'
代替。 您想將char
與char
比較, char
要將char
與char*
。
您應改用while ( a != '|' )
'|'
是字符和"|"
是只有1個字符的字符串
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.