#include <iostream>
#include <string>
#include <sstream>
using namespace std;
int main(void) {
int dado = -1;
string entrada = ""; //melhor ler uma string e tentar converter depois
while (true) {
cout << "Digite um numero inteiro: ";
getline(cin, entrada); //pede um stream de uma linha toda
cout << endl;
stringstream myStream(entrada);
if (!(myStream >> dado)) { //se não conseguir fazer a conversão
cout << "Valor inválido, tente novamente" << endl;
continue;
}
if (dado < 0) break; //se digitar o número que determina encerrar
// inserir(fila, dado); <========== neste ponto você faz o que quiser, o valor é válido
}
}
//https://pt.stackoverflow.com/q/41920/101
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8c3RyaW5nPgojaW5jbHVkZSA8c3N0cmVhbT4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCmludCBtYWluKHZvaWQpIHsKICAgIGludCBkYWRvID0gLTE7CiAgICBzdHJpbmcgZW50cmFkYSA9ICIiOyAvL21lbGhvciBsZXIgdW1hIHN0cmluZyBlIHRlbnRhciBjb252ZXJ0ZXIgZGVwb2lzCiAgICB3aGlsZSAodHJ1ZSkgewogICAgICAgIGNvdXQgPDwgIkRpZ2l0ZSB1bSBudW1lcm8gaW50ZWlybzogIjsKICAgICAgICBnZXRsaW5lKGNpbiwgZW50cmFkYSk7IC8vcGVkZSB1bSBzdHJlYW0gZGUgdW1hIGxpbmhhIHRvZGEKICAgICAgICBjb3V0IDw8IGVuZGw7CiAgICAgICAgc3RyaW5nc3RyZWFtIG15U3RyZWFtKGVudHJhZGEpOwogICAgICAgIGlmICghKG15U3RyZWFtID4+IGRhZG8pKSB7IC8vc2UgbsOjbyBjb25zZWd1aXIgZmF6ZXIgYSBjb252ZXJzw6NvCiAgICAgICAgICAgIGNvdXQgPDwgIlZhbG9yIGludsOhbGlkbywgdGVudGUgbm92YW1lbnRlIiA8PCBlbmRsOwogICAgICAgICAgICBjb250aW51ZTsKICAgICAgICB9CiAgICAgICAgaWYgKGRhZG8gPCAwKSBicmVhazsgLy9zZSBkaWdpdGFyIG8gbsO6bWVybyBxdWUgZGV0ZXJtaW5hIGVuY2VycmFyCi8vICAgICAgICBpbnNlcmlyKGZpbGEsIGRhZG8pOyA8PT09PT09PT09PSBuZXN0ZSBwb250byB2b2PDqiBmYXogbyBxdWUgcXVpc2VyLCBvIHZhbG9yIMOpIHbDoWxpZG8KICAgIH0KfQoKLy9odHRwczovL3B0LnN0YWNrb3ZlcmZsb3cuY29tL3EvNDE5MjAvMTAx