gpt4 book ai didi

C++ Basic while循环,击键退出

转载 作者:搜寻专家 更新时间:2023-10-31 01:01:44 26 4
gpt4 key购买 nike

我是编程新手,这是我的第二个作业。它应该接受用户的输入,直到他们输入 | 退出程序。我做错了什么?

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 进行比较,而不是将 charchar* 进行比较。

关于C++ Basic while循环,击键退出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28467510/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com