Yes, this is safe in this case [as long as the implementation of the stream and operators follow what the standard says they should do]
Of course, if you have different types than int
, say mytype
, and have custom made istream& operator >>(istream&, mytype&)
defined for your class, it's entirely possible to have a bug in the code that causes some/all of the fields of mytype
to be uninitialized.