当前位置: 代码迷 >> 综合 >> vector_ v.resize()+v[i] “vs“ v.push_back(x);
  详细解决方案

vector_ v.resize()+v[i] “vs“ v.push_back(x);

热度:26   发布时间:2023-12-06 05:04:20.0

// 看例子自己品
#include<bits/stdc++.h>
using namespace std;vector<int> v;void out()
{cout<<"size:"<<v.size()<<" - ";for( int i=0;i<v.size();i++ ) cout<<v[i]<<' '; cout<<endl;
}int main()
{int n;while( cin>>n ){if( n==0 ) break; v.clear();v.resize(n);	out();v.push_back(n); out();v.pop_back();   out(); v[1]=n;         out();}return 0;
}
// 4
// size:4 - 0 0 0 0
// size:5 - 0 0 0 0 4
// size:4 - 0 0 0 0
// size:4 - 0 4 0 0

  相关解决方案