我想學習C++中的標準庫,我試圖運行我的代碼,但我無法成功。我忘了什麼,在我的課程「Class」中需要添加哪些內容才能使程序運行?在C++中使用標準庫,複製算法
#include <iostream>
#include <vector>
#include <list>
#include <algorithm>
#include <iterator>
using namespace std;
class Class {
public:
Class (int ii, double dd) : ival(ii) { dval = new double; *dval = dd; }
~Class() { delete dval; }
private:
int ival;
double *dval;
};
int main()
{
vector<Class> vec;
list<Class> list;
vec.push_back(Class(1, 2.2));
vec.push_back(Class(2, 4.3));
vec.push_back(Class(3, 5.7));
ostream_iterator<const Class> classout(cout,"\n");
copy(vec.begin(), vec.end(), classout);
}
基本上,我試圖瞭解並使用複製算法:
template
OutputIterator copy (InputIterator first, InputIterator last,
OutputIterator result)
{
while (first!=last) *result++ = *first++;
return result;
}
@codesinchaos也許你可以幫助我這個嗎?:) – Stabbah