首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

c++ stl为何core?就几行代码。

2012-10-17 
c++ stl为啥core?就几行代码。。#include stdio.h#include string.h#include list#include vectorus

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>

热点排行