请各位大侠指点啊,如何实现两个vector<string>类型的相加?
来源:百度知道 编辑:UC知道 时间:2024/08/24 01:59:28
如何实现两个vector<string>类型的相加?(最好有点简单的代码)
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
void print( const vector<string>& vec1,const vector<string>& vec2 )
{
copy( vec1.begin(),vec1.end(),ostream_iterator< string >( cout," " ));
cout<<endl;
copy( vec2.begin(),vec2.end(),ostream_iterator< string >( cout," " ));
cout<<endl;
}
int main()
{
vector<string> vec1;
vec1.push_back("hahhh");
vec1.push_back("dkkdk");
vector<string> vec2;
vec2.push_back("dkk");
vec2.push_back("djjdj");
print(vec1,vec2);
//方法1:
for( vector<string>::iterator it = vec2.begin();it!=vec2.end();++it )
vec1.push_back(*it);
print(vec1,vec2);
//方法2:
copy( vec2.begin(),vec2.end(),back_insert_iterator<vector<