小编T0M*_*FeR的帖子

C++中的向量:为什么我这个简单的复制和打印程序会出现这么多错误?

我正在尝试使用算法lib和vector lib首先将一组数字从一个数组复制到一个向量中,然后使用迭代打印它,我的代码问题在哪里?

有一件事是我首先使用vec.begin()选择2种方式进行迭代; vec.end()方法和另一个方法是(i = 0; i <vec.capacity(); i ++)都面临错误.

我该怎么办?

#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
    int intArray[] = {5,6,8,3,40,36,98,29,75};

    vector<int> vecList(9);
    //vector<int>::iterator it;
    copy (intArray, intArray+9,vecList);
    //for(it  = vecList.begin() ; it != vecList.end() ; it++)
    for (int it = 0 ; it < vecList.capacity() ; it++)
    {
        cout<<*it<<endl;
     }

    system("pause");
    return 0;

}
Run Code Online (Sandbox Code Playgroud)

c++ iteration stl vector c++11

3
推荐指数
2
解决办法
196
查看次数

标签 统计

c++ ×1

c++11 ×1

iteration ×1

stl ×1

vector ×1