c++ stl为啥core?就几行代码。。
#include <stdio.h>
#include <string.h>
#include <list>
#include <vector>
using namespace std;
int main(){
vector<int> test;
list<int> test1;
test.push_back(1);
test.push_back(2);
test.push_back(3);
test.push_back(4);
std::copy(test.begin(),test.end(),test1.begin());
vector<int>::iterator it = test.begin();
printf("%d\n",*it);
}
我就打印下test.begin都不行?
后来 我换成打印 test1.begin,能打印出值但是值不对啊。。求解释
~
[解决办法]
std::copy(test.begin(),test.end(),test1.begin());
这个会调用operator=来操作的,所以调用之前text1必须有足够的空间
或改为
std::copy(test.begin(),test.end(),test1.begin());//#include<iterator>