| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 391 人关注过本帖
标题:关于 fornt_insert_iterator 问题
只看楼主 加入收藏
寂寞的一角钱
Rank: 2
等 级:论坛游民
帖 子:14
专家分:29
注 册:2014-3-25
结帖率:100%
收藏
已结贴  问题点数:16 回复次数:1 
关于 fornt_insert_iterator 问题
#include <iostream>
#include <string>
#include <iterator>
#include <vector>
#include <algorithm>

void output(const std::string& s)
{
    std::cout << s << " ";
}

int main()
{
    using namespace std;

    string s1[4] = {"fine", "fish", "fashion", "fate"};
    string s2[2] = {"busy", "bats"};
    string s3[2] = {"silly", "singers"};
    vector<string> words(4);

    copy(s1, s1+4, words.begin());
    for_each(words.begin(), words.end(), output);
    cout << endl;

    copy(s2, s2+2, back_insert_iterator< vector<string> >(words));
    for_each(words.begin(), words.end(), output);
    cout << endl;

    copy(s3, s3+2, front_insert_iterator< vector<string> >(words));  // 错误 用法与back_insert_iterator 相同吧?
    for_each(words.begin(), words.end(), output);
    cout << endl;[/color]

    copy(s3, s3+2, insert_iterator< vector<string> >(words, words.begin()));
    for_each(words.begin(), words.end(), output);
    cout << endl;
    return 0;
}
搜索更多相关主题的帖子: fashion include 
2014-04-27 23:25
rjsp
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:版主
威 望:528
帖 子:9007
专家分:53942
注 册:2011-1-18
收藏
得分:16 
// 错误 用法与back_insert_iterator 相同吧?
------ 什么错误你得说明白,以节约大家的时间。
一开始以为你说的是运行结果错误,看了半天没发现问题。
后来一想,你说的可能是编译错误,以这种思路的话,那问题就明显了,vector没有push_front成员,你不能在vector上用front_insert_iterator
2014-04-28 11:56
快速回复:关于 fornt_insert_iterator 问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.011530 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved