为什么 C++ 中没有 std::wostream_iterator?
这有什么好的理由吗?
#include <fstream>
#include <iterator>
#include <string>
#include <vector>
int main()
{
std::vector<std::wstring> myvec = { L"first", L"second" };
std::wofstream f("New.txt");
// std::copy(myvec.begin(), myvec.end(), std::wostream_iterator<std::wstring>(f)); // Error
// std::copy(myvec.begin(), myvec.end(), std::ostream_iterator<std::wstring>(f)); // Error
std::copy(myvec.begin(), myvec.end(), std::ostream_iterator<std::wstring, wchar_t>(f)); // Ok
std::copy(myvec.begin(), myvec.end(), std::ostream_iterator<std::wstring, wchar_t, std::char_traits<wchar_t>>(f)); // Ok
}