How do I check if input is an integer/string?

前端 未结 6 1298
一个人的身影
一个人的身影 2021-01-01 07:33

My problem here is I don\'t know how to insert a rule wherein if a user inputted a number on the string, it will cout a warning saying it\'s not valid, same wit

6条回答
  •  悲&欢浪女
    2021-01-01 08:19

        cout << "\n Enter number : ";
        cin >> ch;
        while (!cin) {
            cout << "\n ERROR, enter a number" ;
            cin.clear();
            cin.ignore(256,'\n');
            cin >> ch;
        }
    

提交回复
热议问题