Maybe not for int
, but for your own types:
class MyType {
int value;
public:
MyType(istream& is) {
is >> *this;
}
friend istream& operator>>(istream& is, MyType& object);
};
istream& operator>>(istream& is, MyType& object) {
return is >> object.value;
}
Then you can create the type with the istream
passed to the constructor:
int main() {
istringstream iss("42");
MyType object(iss);
}