C++入门笔记
- vicyang
- 版主
- 帖子: 56
- 注册时间: 2016年07月21日 20:35
- 拥有现金: 锁定
- 储蓄: 锁定
- Has thanked: 7 times
- Been thanked: 5 times
- 联系:
vector - 向量
- #include <iostream> //input output
- #include <vector> //vector
- #include <algorithm> //sort()
- int main(int argc, char *argv[] )
- {
- using namespace std;
- vector<int> v(5, 100);
- v[0] = 1;
- for (int i = 10; i > 1; i--)
- v.push_back(i);
- sort(v.begin(), v.end()-5); //排序,但是不包括最后5位
- for (int i = 0; i<v.size(); i++)
- std::cout<< v[i] <<std::endl;
- return 0;
- }
Re: C++入门笔记
可以使用通用的方法 std::begin, std::end, 这可以用在更多的情况,普通的数组也能用
std::begin(v), std::end(v), std::begin(array1), std::end(array1)
std::begin(v), std::end(v), std::begin(array1), std::end(array1)
在线用户
用户浏览此论坛: 没有注册用户 和 0 访客