并感谢您查看这篇文章。我的编程需要一些帮助。我曾经用 turbo pascal 编译,现在我正在学习 C++。这就是问题所在。
我想用这样的输入和输出做一个数学的东西。
输入(伪代码):
Var a,b:=int; op:=char;
readln(a);
readln(b);
case op of
"+" : write(a+b);
"-" : write(a-b);
">" : if a>b then write("true"); else write("false");
我曾尝试像这样在 C++ 中执行此操作,但无法编译。我没有把 include 放在这里,因为我真的不明白为什么它变得粗体。我写了这样的东西。
void main()
{
int a,b,c;
char op;
std::cin>>a>>op>>b;
switch (c){
case (std::cin>>op == "+") :{
c=a+b;
std::cout<<c<<std::endl;
}
}
}
这是错误
1>test03.cpp(10): error C2051: case expression not constant
1>test03.cpp(14): warning C4060: switch statement contains no 'case' or 'default' labels
谁能帮帮我?谢谢。