野百合也有春天

导航

mem_fun的用法,以及使用wcout

#include "stdafx.h"
#include <vector>
#include <algorithm>
#include <iostream>
#include <locale>
#include <functional>
using namespace std;

class Widget
{
public:
	Widget(wstring str)
	{
		str_ = str;
	}
	wstring str_;

	void Print()
	{
		wcout<<str_<<endl;
	}
};

void test(Widget &w)
{
	wcout<<w.str_<<endl;
}

int main()
{
	locale loc( "chs" );
	wcout.imbue( loc );
	
	vector<Widget*> w_list;
	Widget w(_T("小的"));
	w_list.push_back(&w);

	Widget w1(_T("大的"));
	w_list.push_back(&w1);


	for_each(w_list.begin(),w_list.end(),mem_fun(&Widget::Print));
	

}

posted on 2010-09-11 20:44  flydream  阅读(417)  评论(0编辑  收藏  举报