All the good time, there was some need for a language that I do not know absolutely. Actually, the task is necessary to make input and output for each type of variable. string accepts any input, double also accepts any number, but what about int? I made it so that it did not accept the string, but when you enter a real, the program breaks down. How to be in this situation? Here is the piece of the program ..

List<int> mylist(0); while (true) { int r; cout<<"Реализация списка для типа Int"<<endl; cout<<"1) Добавить элемент"<<endl; ................... cin>>r; if (r==0) {mylist.~List();break;} switch (r) { case 1: { int st; cout<<"Введите элемент"<<endl; while (!(cin >> st)) { cin.clear(); while (cin.get() != '\n'); cout << "Неверный ввод. Повторите." << endl; cout <<"Введите целое число "<< endl; } mylist.add(st); system("pause"); continue; } ....................... } 
  • In general, for complete control, it is probably worth reading the entire line that you have entered, and then you have to figure out whether it is correct or not, take apart, etc. - Alexey Sarovsky
  • Even if I sort it out. What should I do about it? Is there any function to check for integerness or something similar? For example, as in ruby x = 10; x.is_a? Integer #true x = 10; x.is_a? Integer #true x = 10; x.is_a? Integer #true - QWD666
  • Checks for integer WHAT? Strings? Actually, you were offered to check the entered string for correctness (using regexp, for example), and then, depending on the result of the check, either translate the string into a number using the atoi function, or generate an error. - Flowneee
  • If you do not particularly bother, it is easier to read as real, and then check whether it is whole or not. For example: double r; int i; ... cin >> r; i = r; if (i != r) error("Not integer"); ... double r; int i; ... cin >> r; i = r; if (i != r) error("Not integer"); ... double r; int i; ... cin >> r; i = r; if (i != r) error("Not integer"); ... - avp
  • one
    Look in the direction of strtol - it says there, where the integer value ended, and if there are any digits left after it or something else - consider the input incorrect. - Harry

0