c++ - Input vector without temporary variable -
this question has answer here:
- getting input directly vector in c++ 5 answers
how input vector without temporary variable(like x in example)?
std::vector<int> a; int n, x; std::cin >> n; (int i=0;i<n;i++) { std::cin >> x; a.push_back(x); }
one possible solution:
int n, x; std::cin >> n; std::vector<int> a(n); (int i=0;i<n;i++){ std::cin >> a[i]; }
Comments
Post a Comment