Boost logo

Boost Users :

From: Richard_Cox_at_[hidden]
Date: 2005-02-04 11:46:20


The program below outputs

  String: <First string> Second string> Fourth string> Fifth string>

All but the first "<" is missing. Any ideas?

(On vc++7.1 using Boost 1.32.0.)

Richard
All opinions are mine and do not represent in any way the position of
Dell Corporation.

#include <ostream>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

#include <boost/lambda/lambda.hpp>

using std::wstring;
using std::wcout;
using std::endl;

using boost::lambda::_1;

typedef std::vector<wstring> StringCollection;

wstring gt(L"<");
std::wostream& operator << (std::wostream& out, StringCollection const&
coll) {
    std::for_each(coll.begin(), coll.end(), out << gt << _1 << L"> ");
    return out;
}

int main(int, char*[]) {
    StringCollection s;
    s.push_back(L"First string");
    s.push_back(L"Second string");
    s.push_back(L"Fourth string");
    s.push_back(L"Fifth string");

    wcout << L"String: " << s << endl;

    return 0;
}


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net