#include "stdafx.h" #include <iostream.h> #include <stdlib.h> // Need random(), srandom() #include <stdio.h> #include <string.h> #include <time.h> // Need time() #include <algorithm> // Need sort(), copy() #include <vector> // Need vector using namespace std; void Display(vector<int>& v, const char* s); // Display label s and contents of integer vector v void Display(vector<int>& v, const char* s) { cout << endl << s << endl; copy(v.begin(), v.end(), ostream_iterator<int>(cout, "\t")); cout << endl; } int main(int argc, char* argv[]) { // Seed the random number generator srand( time(NULL) ); // Construct vector and fill with random integer values vector<int> collection(10); for (int i = 0; i < 10; i++) collection[i] = rand() % 10000;; // Display, sort, and redisplay Display(collection, "Before sorting"); sort(collection.begin(), collection.end()); Display(collection, "After sorting"); return 0; }
运行结果:error C2665: 'ostream_iterator<int,char,struct std::char_traits<char> >::ostream_iterator<int,char,struct std::char_traits<char> >' : none of the 2 overloads can convert parameter 1 from type 'class ostream_withassign'
执行 cl.exe 时出错.
解决方案:修改头文件#include<iostream.h>为#include<iiostream>