#include <iostream>
#include <vector>
using std::cout;
using std::endl;
using std::vector;
int main()
{
vector<int> ivec;
int val;
for (vector<int>::size_type ix = 0;
ix != 10; ++ix)
ivec.push_back(ix);
cout << "ivec.size: " << ivec.size() << endl;
if (ivec.empty() == false) {
for (vector<int>::size_type ix = 0;
ix != ivec.size(); ++ix)
cout << ivec[ix] << endl;
}
return 0;
}
输出:
pateo@pateo-B86N53X:~/work/study$ g++ -o main main.cc
pateo@pateo-B86N53X:~/work/study$ ./main
ivec.size: 10
0
1
2
3
4
5
6
7
8
9
#include <iostream>
#include <vector>
using std::cout;
using std::endl;
using std::vector;
int main()
{
vector<int> ivec;
int val;
for (vector<int>::size_type ix = 0;
ix != 10; ++ix)
ivec.push_back(ix);
cout << "ivec.size: " << ivec.size() << endl;
for (vector<int>::size_type ix = 0; ix != ivec.size(); ++ix)
ivec[ix] = 0;
if (ivec.empty() == false) {
for (vector<int>::size_type ix = 0;
ix != ivec.size(); ++ix)
cout << ivec[ix] << endl;
}
return 0;
}
输出:
pateo@pateo-B86N53X:~/work/study$ g++ -o main main.cc
pateo@pateo-B86N53X:~/work/study$ ./main
ivec.size: 10
0
0
0
0
0
0
0
0
0
0