#include <stdlib.h>
#include <stdio.h>
#include <vector>
#include <iostream>
using namespace std;
int main(int argc, char* *argv)
{
vector<int> vct;
vct.push_back(100);
vct.push_back(100);
vct.push_back(100);
vct.push_back(100);
vct.push_back(100);
vct.push_back(100);
vct.push_back(100);
vct.push_back(100);
for ( int& value : vct )
{
cout << value << endl;
}
return 1;
}
[~/test]g++ -std=c++11 1.cpp
[~/test]./a.out
100
100
100
100
100
100
100
100

本文展示了如何使用C++标准库中的vector容器进行元素遍历及输出,通过实例代码演示了向量操作的基本用法。

2874

被折叠的 条评论
为什么被折叠?



