C++ “你好”;while(选项未运行)“;在C++;
我试图用C++制作一个计算器,并尽可能地压缩它。我不知道如何将“whilechoice not in operation”从Python翻译成C++C++ “你好”;while(选项未运行)“;在C++;,c++,arrays,while-loop,C++,Arrays,While Loop,我试图用C++制作一个计算器,并尽可能地压缩它。我不知道如何将“whilechoice not in operation”从Python翻译成C++ #include <iostream> #include <string> using namespace std; string operation[] = { "+","-","/","*" }; string choice; int main(){
#include <iostream>
#include <string>
using namespace std;
string operation[] = { "+","-","/","*" };
string choice;
int main(){
while (choice not in operation) {
cout << "Enter the operation that you want to use(/,*,+,-): ";
cin >> operation;
}
}
#包括
#包括
使用名称空间std;
字符串操作[]={“+”,“-”,“/”,“*”};
字符串选择;
int main(){
while(选项未运行){
cout>操作;
}
}
这是惯用的C++语言,高效且相当简洁:
while (find(begin(operation), end(operation), choice) == end(operation))
可能会有帮助