Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ “你好”;while(选项未运行)“;在C++;_C++_Arrays_While Loop - Fatal编程技术网

C++ “你好”;while(选项未运行)“;在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(){

我试图用C++制作一个计算器,并尽可能地压缩它。我不知道如何将“whilechoice not in operation”从Python翻译成C++

    #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))
可能会有帮助