Originariamente inviato da internet
ho provato la soluzione che hai proposto e praticamente l'espressione nell'if risulta sempre falsa anche mettendo stringhe di caratteri alfabetici.

Mettendo dei caratteri come input dopo la
cin >> n;
la variabile n essendo di tipo int non viene modificata e assume lo stesso valore che aveva prima della cin, 0 nel caso del codice di Guglie
0xBAADF00D nel caso mio che non l'ho inizializzata

fail() è un metodo pubblico di

codice:
class basic_ios: public ios_base {
public:
  ...
  bool good() const;    // next operation might succeed
  bool eof() const;     // end of input seen
  bool fail() const; // next operation will fail
  bool bad() const;     // stream is corrupted
  ...
}
dallo Stroustrup
If the state is good() the previous input operation succeded. If the state is good(), the next input operation might succed; otherwise, it will fail. Applying an input operation to a stream that is not in the good() state is a null operation. If we try to read a variable v and the operation fails, the value of v should be unchanged (it is unchanged if v is a variabile of one of the type handled by istream or ostream member functions). The difference between the states fail() and bad() is subtle. When the state is fail() but not also bad(), it is assumed that the stream is uncorrupted and that no characters have been lost. When the state is bad(), all bets are off.
ah io xchè in genere programmo in C quindi usando scanf("%d",&n); il controllo con casting da me fatto è giusto? mi spieghi l'errore logico che ho fatto?
Per capire anche se nn è importantissimo

Grazie mille