鱼C论坛

 找回密码
 立即注册
查看: 1706|回复: 0

关于front_insert_iterator的问题

[复制链接]
发表于 2014-4-27 23:27:07 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
#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));   //错误
    for_each(words.begin(), words.end(), output);
    cout << endl;

    copy(s3, s3+2, insert_iterator< vector<string> >(words, words.begin()));
    for_each(words.begin(), words.end(), output);
    cout << endl;
    return 0;
}


想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-11-24 05:20

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表