c++ - How to read exactly one line? -
I have a Linux file descriptor (from the socket), and I have to read a line how to do it in C ++?
I am reading from a TCP socket which you can not assume will reach the end of the line. So you'll need something for this:
std :: string line; Four buff [1024]; Int n = 0; While {n = read (fd, buf, 1024)) {const int pos = std :: find (buf, buf + n, '\ n') if (pos! Std :: string :: npos) {if (position & Amp; 1024; & amp; amp; amp; amp; [FG + 1] == '\ n') Break; } Line + = buff; } Line + = buff;
Assume that you are using "\ n \ n" as a delimiter. (I did not test that code snippet ;-))
On an UDP socket, this is another story Emiter can send a packet containing a full line Receiver to receive the Pentate as a unit If it is received, then UDP is not as reliable as TCP.
Comments
Post a Comment