内容纲要
#include <iostream>
#include <vector>
#include <list>
#include <algorithm>
#include <iterator>

using namespace std;

void main() {
    vector<int> v1;
    v1.push_back(9);
    v1.push_back(8);
    v1.push_back(7);
    v1.push_back(6);
    v1.push_back(5);
    v1.push_back(4);
    v1.push_back(3);
    v1.push_back(2);
    v1.push_back(1);
    v1.push_back(0);
    vector<int>::iterator it;
    for (it = v1.begin(); it != v1.end(); it++) {
        cout << *it << endl;
    }
    for (int i = 0; i < v1.size(); i++)
    {
        cout << v1[i] << endl;
    }
        cout << "————————————————" << endl;
    v1.erase(v1.begin() + 4);
    for (int i = 0; i < v1.size(); i++)
    {
        cout << v1[i] << endl;
    }
    cout << "————————————————" << endl;
    v1[4] = 99;
    for (int i = 0; i < v1.size(); i++)
    {
        cout << v1[i] << endl;
    }
    cout << "————————————————" << endl;
    it = find(v1.begin(), v1.end(), 3);
    if (it == v1.end())
    {
        cout << "未找到" << endl;
        cout << "————————————————" << endl;
    }
    else
        cout << *it << endl;
    cout << "————————————————" << endl;
    copy(v1.begin(), v1.end(), ostream_iterator<int>(cout, "\n"));
    cout << "————————————————" << endl;
    sort(v1.begin(), v1.end());
    copy(v1.begin(), v1.end(), ostream_iterator<int>(cout, "\n"));

    list<int> l1;
    for (int i = 0; i < 10; i++) {
        l1.push_back(rand());
    }
    copy(l1.begin(), l1.end(), ostream_iterator<int>(cout, "\n"));
    l1.sort();
    copy(l1.begin(), l1.end(), ostream_iterator<int>(cout, "\n"));

    system("pause");
}

问题

copy(v1.begin(), v1.end(), ostream_iterator(cout, "\n"));
这段代码显示错误,但是老师里的视频里是可以通过的,是不是少了什么头文件之类的东西?

已解决

添加“头文件

1 对 “STL 里ostream_iterator用不了”的想法;

  1. Pingback: buy viagra

发表评论