gpt4 book ai didi

c++ - 字符到运算符 C++

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:19:28 26 4
gpt4 key购买 nike

嘿,我想知道如何将字符“+”变成运算符。例如,如果我有

char op = '+'
cout << 6 op 1;

谢谢。

最佳答案

简单的方法是使用 switch 语句

switch (op)
{
case '+':
res = x + y;
break;
case '-':
res = x - y;
break;
case '*':
res = x * y;
break;
}

关于c++ - 字符到运算符 C++,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13142270/

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