I want to know that is there any way that we can insert a multiple values in a vector as a single value without using a temp variable?
I mean for example:
struct Something{
int x;
int y;
};
int main()
{
vector <Something> v;
int x, y;
cin >> x >> y;
v.push_back(x, y);
}
Is there any way that we avoid doing this(defining another variable, then inserting that, instead of insert x, y directly):
Something temp;
temp.x = x;
temp.y = y;
v.push_back(temp);
Give your class a constructor, like this:
Then you can just do this:
In C++11, you can do this, without the constructor: