I have a Linux file descriptor (from socket), and I want to read one line. How to do it in C++?

This Comment will be submitted for moderation and will not be accessible to other users until it has been approved.


22 points

I have a Linux file descriptor (from socket), and I want to read one line at a time. How to do it in C++?



17 points

 

<cpp>
char newline = '\n';
file fd
;
initialize
(fd);
string line;
char c;
while( newline != (c = readchar(fd)) ) {
 line
.append(c);
}
</cpp>

Something like that.

Thomas j's picture
Created by Thomas j

Post Comment

  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>, <c>, <cpp>, <drupal5>, <drupal6>, <java>, <javascript>, <php>, <python>, <ruby>. Beside the tag style "<foo>" it is also possible to use "[foo]". PHP source code can also be enclosed in <?php ... ?> or <% ... %>.