【发布时间】:2016-11-10 10:44:16
【问题描述】:
我正在尝试编写一个程序,该程序可以通过网络将数据发送到我的 Java 服务器上侦听一个端口。
#include "stdafx.h"
#include <boost/asio.hpp>
#include <boost/array.hpp>
#include <iostream>
void do_somenetwork(std::string host, int port, std::string message)
{
std::array<char, 1024> _arr;
boost::asio::io_service ios;
boost::asio::ip::tcp::endpoint endpoint(boost::asio::ip::address::from_string(host), port);
boost::asio::ip::tcp::socket socket(ios);
socket.connect(endpoint);
boost::array<char, 128> buf;
std::copy(message.begin(), message.end(), buf.begin());
boost::system::error_code error;
socket.write_some(boost::asio::buffer(buf, message.size()), error);
socket.read_some(boost::asio::buffer(_arr));
std::cout.write(&_arr[0], 1024);
socket.close();
}
int main(){
do_somenetwork(std::string("127.0.0.1"), 50000, ";llsdfsdf");
char ch;
std::cin >> ch;
}
当我使用这个程序时,我不断收到如下错误消息:
C4996: 'std::_Copy_impl': Function call with parameters that may be unsafe - this call relies on the caller to check that the passed values are correct. To disable this warning, use -D_SCL_SECURE_NO_WARNINGS. See documentation on how to use Visual C++ 'Checked Iterators' c:\program files (x86)\microsoft visual studio 12.0\vc\include\xutility 2132 1 ConsoleApplication1
我已尝试警告,但未找到与此错误相关的任何结果。有没有更好的方法来编写这段代码?我对 C++ 真的很陌生,并且对 Boost 的实际工作方式不太了解。 我正在使用 Visual Studio 2013 并提升 1.60.0。
【问题讨论】:
标签: c++ boost boost-asio