In C ++ 11, you can use placement functions:
if (std::cin >> x >> y) { v.emplace_back(x, y); } else { }
This assumes your Something class has a constructor (int, int) . Otherwise, you can use push_back with a parenthesis initializer, as in Benjamin's answer. (Both versions will likely generate identical code when working with the smart compiler, and you may like to save your class as a collection.)
source share