boost库asio tcp 网络编程解决办法

boost库asiotcp 网络编程源代码:// chatSer.cpp : 定义控制台应用程序的入口点。//#include stdafx.h#inc

boost库asio tcp 网络编程
源代码:
// chatSer.cpp : 定义控制台应用程序的入口点。
//

#include "stdafx.h"
#include<iostream>
#include<string.h>
#include <boost/asio.hpp>
#include<boost/system/error_code.hpp>

using namespace boost::asio;
using namespace std ;
class client
{
  private:
io_service &ios;
ip::tcp::endpoint ep;
char bufRec[300];
char bufGet[200];
  char bufSed[300];
char bufTime[10];
char bufDate[20];
typedef shared_ptr<ip::tcp::socket> sock_pt;
  public :
client(io_service &io):ios(io),ep(ip::address::from_string("127.0.0.1"),8568)
{
start();
}
void start()
{
sock_pt sock(new ip::tcp::socket(ios));
sock->async_connect(ep,bind(&client::conn_handler,this,boost::asio::placeholders::error,sock));
}
void conn_handler(const boost::system::error_code &ec,sock_pt sock,char buf[200])
{
if(ec)
{
return ;
}
cout<<sock->remote_endpoint().address()<<endl;
shared_ptr<vector<char>> str(new vector<char>(100,0));
sock->async_read_some(buffer(*str),bind(&client::read_handler,this,boost::asio::placeholders::error,str));
start();
}
void read_handler(const boost::system::error_code &ec,shared_ptr<vector<char>>str)
{
if(ec)
{
return ;
}
cout<<&(*str)[0]<<endl;
}
};
int main()
{
try
{
cout<<"客户端启动!"<<endl;
io_service ios;
client cl(ios);
ios.run();
}catch(std::exception&e)
{
cout<<e.what()<<endl;
}

}

编译的时候老是报这样的错误,前辈们能不能说说这样的错误到底是什么原因?是那些方面引起的? 本人接触boost 第5天,真都不太懂,为什么老是说源文件的错误呢???

所有输出均为最新。
1> chatCli.cpp
1>e:\vs\vc\include\xxresult(28): error C2825: '_Fty': 当后面跟“::”时必须为类或命名空间
1> e:\vs\vc\include\xxresult(40): 参见对正在编译的类 模板 实例化“std::tr1::_Result_type3<__formal,_Fty,_Arg0,_Arg1,_Arg2>”的引用
1> with
1> [
1> __formal=false,
1> _Fty=void (__thiscall client::* )(const boost::system::error_code &,client::sock_pt,char []),
1> _Arg0=std::tr1::_Nil &,
1> _Arg1=std::tr1::_Nil &,
1> _Arg2=std::tr1::_Nil &
1> ]
1> e:\vs\vc\include\xxresult(597): 参见对正在编译的类 模板 实例化“std::tr1::_Result_of3<_Fty,_Farg0,_Farg1,_Farg2>”的引用
1> with
1> [
1> _Fty=void (__thiscall client::* )(const boost::system::error_code &,client::sock_pt,char []),
1> _Farg0=std::tr1::_Nil &,
1> _Farg1=std::tr1::_Nil &,
1> _Farg2=std::tr1::_Nil &
1> ]
1> e:\vs\vc\include\xrefwrap(28): 参见对正在编译的类 模板 实例化“std::tr1::_Result_of<_Ty>”的引用
1> with
1> [
1> _Ty=void (__thiscall client::* (std::tr1::_Nil &,std::tr1::_Nil &,std::tr1::_Nil &))(const boost::system::error_code &,client::sock_pt,char [])
1> ]
1> e:\vs\vc\include\xxbind1(273): 参见对正在编译的类 模板 实例化“std::tr1::result_of<_Fty>”的引用
1> with
1> [
1> _Fty=void (__thiscall client::* (std::tr1::_Nil &,std::tr1::_Nil &,std::tr1::_Nil &))(const boost::system::error_code &,client::sock_pt,char [])
1> ]
1> e:\vs\vc\include\xxbind0(10): 参见对正在编译的类 模板 实例化“std::tr1::_Bind3<_Callable,_Arg0,_Arg1,_Arg2>::_Return<_Barg0,_Barg1,_Barg2,_Barg3,_Barg4,_Barg5,_Barg6,_Barg7,_Barg8,_Barg9>”的引用
1> with
1> [


1> _Callable=std::tr1::_Callable_obj<void (__thiscall client::* )(const boost::system::error_code &,client::sock_pt,char []),false>,
1> _Arg0=client *,
1> _Arg1=boost::arg<1>,
1> _Arg2=client::sock_pt,
1> _Barg0=std::tr1::_Nil &,
1> _Barg1=std::tr1::_Nil &,
1> _Barg2=std::tr1::_Nil &,
1> _Barg3=std::tr1::_Nil &,
1> _Barg4=std::tr1::_Nil &,
1> _Barg5=std::tr1::_Nil &,
1> _Barg6=std::tr1::_Nil &,
1> _Barg7=std::tr1::_Nil &,
1> _Barg8=std::tr1::_Nil &,
1> _Barg9=std::tr1::_Nil &
1> ]
1> e:\vs\vc\include\functional(408): 参见对正在编译的类 模板 实例化“std::tr1::_Bind_base<_Ret,_BindN>”的引用
1> with
1> [
1> _Ret=std::tr1::_Notforced,
1> _BindN=std::tr1::_Bind3<std::tr1::_Callable_obj<void (__thiscall client::* )(const boost::system::error_code &,client::sock_pt,char []),false>,client *,boost::arg<1>,client::sock_pt>
1> ]
1> g:\程序\boost\chatcli\chatcli\chatcli.cpp(83): 参见对正在编译的类 模板 实例化“std::tr1::_Bind_fty<_Fty,_Ret,_BindN>”的引用
1> with
1> [
1> _Fty=void (__thiscall client::* )(const boost::system::error_code &,client::sock_pt,char []),
1> _Ret=std::tr1::_Notforced,
1> _BindN=std::tr1::_Bind3<std::tr1::_Callable_obj<void (__thiscall client::* )(const boost::system::error_code &,client::sock_pt,char []),false>,client *,boost::arg<1>,client::sock_pt>
1> ]
1>e:\vs\vc\include\xxresult(28): error C2903: “result”: 符号既不是类 模板 也不是函数 模板
1>e:\vs\vc\include\xxresult(28): error C2039: “result”: 不是“`global namespace'”的成员
1>e:\vs\vc\include\xxresult(28): error C2143: 语法错误 : 缺少“;”(在“<”的前面)
1>e:\vs\vc\include\xxresult(28): error C2039: “type”: 不是“`global namespace'”的成员
1>e:\vs\vc\include\xxresult(28): error C2238: 意外的标记位于“;”之前
1>e:\vs\vc\include\xxresult(40): error C2039: “_Type”: 不是“std::tr1::_Result_type3<__formal,_Fty,_Arg0,_Arg1,_Arg2>”的成员
1> with
1> [
1> __formal=false,
1> _Fty=void (__thiscall client::* )(const boost::system::error_code &,client::sock_pt,char []),
1> _Arg0=std::tr1::_Nil &,
1> _Arg1=std::tr1::_Nil &,
1> _Arg2=std::tr1::_Nil &
1> ]
1>e:\vs\vc\include\xxresult(40): error C2146: 语法错误: 缺少“;”(在标识符“_Type”的前面)
1>e:\vs\vc\include\xxresult(40): error C4430: 缺少类型说明符 - 假定为 int。注意: C++ 不支持默认 int
1>e:\vs\vc\include\xxresult(40): error C2602: “std::tr1::_Result_of3<_Fty,_Farg0,_Farg1,_Farg2>::_Type”不是“std::tr1::_Result_of3<_Fty,_Farg0,_Farg1,_Farg2>”基类的成员
1> with
1> [
1> _Fty=void (__thiscall client::* )(const boost::system::error_code &,client::sock_pt,char []),
1> _Farg0=std::tr1::_Nil &,
1> _Farg1=std::tr1::_Nil &,
1> _Farg2=std::tr1::_Nil &
1> ]
1> e:\vs\vc\include\xxresult(40) : 参见“std::tr1::_Result_of3<_Fty,_Farg0,_Farg1,_Farg2>::_Type”的声明
1> with
1> [
1> _Fty=void (__thiscall client::* )(const boost::system::error_code &,client::sock_pt,char []),
1> _Farg0=std::tr1::_Nil &,
1> _Farg1=std::tr1::_Nil &,
1> _Farg2=std::tr1::_Nil &
1> ]
1>e:\vs\vc\include\xxresult(40): error C2868: “std::tr1::_Result_of3<_Fty,_Farg0,_Farg1,_Farg2>::_Type”: 非法的 using 声明语法;应输入限定名


1> with
1> [
1> _Fty=void (__thiscall client::* )(const boost::system::error_code &,client::sock_pt,char []),
1> _Farg0=std::tr1::_Nil &,
1> _Farg1=std::tr1::_Nil &,
1> _Farg2=std::tr1::_Nil &
1> ]
1>
1>生成失败。
1>
1>已用时间 00:00:11.72
========== 生成: 成功 0 个,失败 1 个,最新 0 个,跳过 0 个 ==========



[解决办法]
1、
#include <boost/smart_ptr/shared_ptr.hpp>

using namespace boost;

2、
shared_ptr<vector<char>>str
改为
shared_ptr<vector<char> >str
[解决办法]
#include <iostream>
#include <string>
#include <vector>
#include <boost/shared_ptr.hpp>
#include <boost/asio.hpp>
#include <boost/system/error_code.hpp>
#include <WinSock2.h>

using namespace boost::asio;
using boost::shared_ptr;
using std::vector;
using std::cout;
using std::endl;

这样会好很多。不过bind哪一行仍然编译不过。