help-gplusplus
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

How to have generic character literals?


From: Siegfried
Subject: How to have generic character literals?
Date: 7 Aug 2006 14:02:49 -0700
User-agent: G2/0.2

Here is my attempt to write a generic output function but it does not
compile. Can someone correct it for me? The problem is with the call to
widen.

Also, is it possible to make this more generic so it is not specific to
class vector?

Thanks,
Siegfried

template<typename CH, typename TY>
std::basic_ostream<CH>& operator<<(std::basic_ostream<CH>& cout, const
std::vector<TY>& vec){
    std::copy(vec.begin(),vec.end(),
std::ostream_iterator<TY,CH>(cout,cout.widen(',')));
    //for(typename std::vector<TY>::const_iterator pE = vec.begin(); pE
!= vec.end(); pE++) cout<<(pE == vec.begin()?"[":",")<<*pE;  cout
<<"]";
    return cout;
}



reply via email to

[Prev in Thread] Current Thread [Next in Thread]