C++11 有没有办法进行字符/字符串限制?

C++11 有没有办法进行字符/字符串限制?,c++11,user-input,restriction,C++11,User Input,Restriction,//想法是,如何限制用户使用这些特定符号?p、 编号为1/2的iput中的s为:10有效,而D10无效 do { //Input cout << "Enter first the arithmatic operation (+, -, *, /, %) and then both operands: "; cin >> operation; cin >> num_1; cin>> num_2;

//想法是,如何限制用户使用这些特定符号?p、 编号为1/2的iput中的s为:10有效,而D10无效

do
    {
        //Input
        cout << "Enter first the arithmatic operation (+, -, *, /, %) and then both operands: "; cin >> operation; cin >> num_1; cin>> num_2;
        if (cin.fail()) {
            cin.clear();
            cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
            continue;
        }

    } while (   (operation != '+' && operation != '-' && operation != '*' && operation != '/' && operation != '%' )
            && ((num_1 <= '0' || num_1 <= '9') || (num_1 >= 'A' && num_1 <= 'F'))
            && ((num_2 >= '0' && num_2 <= '9') || (num_2 >= 'A' && num_2 <= 'F'))   );
do
{
//输入
cout>操作;cin>>数量1;cin>>数量2;
if(cin.fail()){
cin.clear();
cin.ignore(std::numeric_limits::max(),'\n');
继续;
}
}while((操作!='+'&&operation!='-'&&operation!='*'&&operation!='/'&&operation!='%'))

&&((num_1标准库几乎无法控制这些内容

这是一个老版本,但readline仍然是我的目标,无论何时我需要一个新奇的输入:

#包括
#包括
#包括
int snuff_键(int,int){返回0;}
bool是允许的(字符c){

返回(c>='0'&&c='A'&&c您不能限制用户输入任何内容。您能做的最好的事情是检查输入是否有效。如果有效,继续使用它。如果无效,报告错误并等待用户输入有效输入。@R Sahu好的,在这种情况下我该如何做?因为如果您输入无效的输入,我仍会执行一次,并且我会执行c我不知道如何检查循环itI是否无效我打赌当我输入
é
:)时,这将非常混乱@Quentin是一个类似的库,支持unicode,但我从未使用过它。@parktomatomi我忘了说,我需要找到一种不用数组、指针等的方法,只使用基本语法。你不必编写它,如果你有想法,我会很高兴的