about vector

jp1984 2004-04-08 11:32:29
这是WILLIAM TOPP 和WILLIAM FORD 那本数据结构 课后的一道题,合并两个向量而已。下面是我写的。刚开始用STL,很不熟练。。不知道为什么向量无法初始化。-》我用数组初始化向量。。
************************************************************************
#include "stdafx.h"
#include<iostream>
#include<vector>
using namespace std;
//join two vectors
template<typename T>
void join(vector<T>& va,const vector<T>& vb)
{
for(int i=0;i<vb.size;i++)

va.push_back(vb[i]);
}
template<typename T>
void writeVector(const vector<T>& v)
{
for(int i=0;i<v.size();i++)
cout<<v[i]<<endl;
}
int main()
{
int arr[]={1,2,3,4,5};
int arrSize=sizeof(arr)/sizeof(int);
vector<int> va=(arr,arr+arrSize);//好象有错误
int _arr[]={5,6,7,8,9};
int _arrSize=sizeof(_arr)/sizeof(int);
vector<int> vb=(_arr,_arr+_arrSize);//有错误???

join(va,vb);
writeVector(va);
return 0;
}//*love myj*

向量到底有几个构造函数???分别是怎样的作用。。 谢谢了。!!
...全文
69 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
jp1984 2004-04-09
  • 打赏
  • 举报
回复
不是吧?? 一天了都没有稍微看一下??
jp1984 2004-04-09
  • 打赏
  • 举报
回复
晕。。这么简单的问题。。我居然没有看到。 //谢谢了。 。 。
weixiaohua 2004-04-09
  • 打赏
  • 举报
回复
你的构造函数用法不对的!
weixiaohua 2004-04-09
  • 打赏
  • 举报
回复
#include<iostream>
#include<vector>
using namespace std;
//join two vectors
template<typename T>
void join(vector<T>& va,const vector<T>& vb)
{
for(int i=0;i<vb.size(); i++)
va.push_back(vb[i]);
}


template<typename T>
void writeVector(const vector<T>& v)
{
for(int i=0; i<v.size(); i++)
cout<<v[i]<<endl;
}


int main()
{
int arr[]={1,2,3,4,5};
int arrSize=sizeof(arr)/sizeof(int);
vector<int> va(arr,arr+arrSize);//改了
int _arr[]={5,6,7,8,9};
int _arrSize=sizeof(_arr)/sizeof(int);
vector<int> vb(_arr,_arr+_arrSize);//改了

join(va,vb);
writeVector(va);
return 0;
}//*love myj*
About This Book, Use Python and QGIS to create and transform data, produce appealing GIS visualizations, and build complex map layoutsLearn undocumented features of the new QGIS processing moduleA set of user-friendly recipes that can automate the entire geospatial workflows by connecting Python GIS building blocks into comprehensive processes, Who This Book Is For, If you are a geospatial analyst who wants to learn more about automating everyday GIS tasks or a programmer who is responsible for building GIS applications,this book is for you. The short, reusable recipes make concepts easy to understand. You can build larger applications that are easy to maintain when they are put together., What You Will Learn, Build a library of reusable scripts with ScriptRunner Create, import, and edit geospatial data on disk or in memory Get to know more about dynamic mapping Create and add features to static maps Create a mapbook Reproject a vector layer Geolocate photos on a map Combine multiple rasters into one image, In Detail, QGIS Python Programming will teach you how to write Python code that works with spatial data to automate geoprocessing tasks in QGIS. It will cover topics such as querying and editing vector data and using raster data. You will also learn to create, edit, and optimize a vector layer for faster queries, reproject a vector layer, reduce the number of vertices in a vector layer without losing critical data, and convert a raster to a vector. Following this, you will come across recipes that will help you to compose static maps, create heavily customized maps, and add specialized labels and annotations. Apart from this, the book will also share a few tips and tricks based on different aspects of QGIS.

65,208

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧