我想使用ostream_iterator將對的向量寫入file.ostream_iterator需要在聲明時應用模板參數。 將載體原樣ostream_iterator的模板參數 - 每個元素都是對
vector<pair<string,long>> test;
定義。當我通過對作爲模板的ostream_iterator它顯示了一個錯誤 -
錯誤1錯誤C2679:二進制「< <」:沒有操作員發現它需要一個'const std :: pair < _Ty1,_Ty2>'的右手操作數(或者沒有可接受的轉換)C:\ Program Files(x86)\ Microsoft Visual Studio 10.0 \ VC \ include \ iterator 531 1 wordsegmentation
在這種情況下,什麼可能是正確的論點?
編輯 - 代碼段
vector<pair<string,long>> t;
......
//t is filled up with elements
ostream_iterator<pair<string,long>> output_iterator(out, "\n");
std::copy(t.begin(), t.end(), output_iterator);
顯示您正在調用'ostream_iterator'的實際代碼。 – Yuushi
[std :: copy to std :: cout for std :: pair]可能重複(http://stackoverflow.com/questions/634087/stdcopy-to-stdcout-for-stdpair) –
可能的[Pretty-打印C + + STL容器](http://stackoverflow.com/questions/4850473/pretty-print-c-stl-containers) – juanchopanza