简体   繁体   中英

boost asio tcp ip write

I am using this code http://www.boost.org/doc/libs/1_42_0/doc/html/boost_asio/tutorial/tutdaytime1/src.html in order to make a client and talk to a server.

I am using the following code to send a message

   boost::asio::write(socket, boost::asio::buffer(msg), ignored_error);

The problem that I have is that if I declare a string msg= "test 123"; and send it, the server will get "test 123" But if if use cin << msg and input test 123 the server receives two messages :

   test
   123

The same applies for char[]

I am compiling at C++ 11 if it does matter using -lboost_system parameters

Input with >> separates on space. So input like test 123 will need two reads using >> .

If you want to read a whole line then use std::getline .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM